2
我剛剛買了synology NAS(DS213J),我試圖在上面運行一個python腳本。Python urlopen錯誤
我的python腳本:
1 #!/opt/bin/python
2
3 import urllib
4 response = urllib.urlopen('http://google.com')
5 html = response.read()
6 print html
當我運行該腳本,我得到這個輸出:
Traceback (most recent call last):
File "/opt/bin/test.py", line 4, in <module>
response = urllib.urlopen('http://google.com')
File "/opt/lib/python2.5/urllib.py", line 82, in urlopen
return opener.open(url)
File "/opt/lib/python2.5/urllib.py", line 190, in open
return getattr(self, name)(url)
File "/opt/lib/python2.5/urllib.py", line 272, in open_http
import httplib
File "/opt/lib/python2.5/httplib.py", line 70, in <module>
import mimetools
File "/opt/lib/python2.5/mimetools.py", line 6, in <module>
import tempfile
File "/opt/lib/python2.5/tempfile.py", line 33, in <module>
from random import Random as _Random
File "/opt/lib/python2.5/random.py", line 58, in <module>
SG_MAGICCONST = 1.0 + _log(4.5)
OverflowError: math range error
我也嘗試過使用的urllib2沒有成功。
腳本:
1 #!/opt/bin/python
2
3 import urllib2
4 response = urllib2.urlopen('http://google.com')
5 html = response.read()
6 print html
控制檯輸出:
Traceback (most recent call last):
File "/opt/bin/test.py", line 3, in <module>
import urllib2
File "/opt/lib/python2.5/urllib2.py", line 92, in <module>
import httplib
File "/opt/lib/python2.5/httplib.py", line 70, in <module>
import mimetools
File "/opt/lib/python2.5/mimetools.py", line 6, in <module>
import tempfile
File "/opt/lib/python2.5/tempfile.py", line 33, in <module>
from random import Random as _Random
File "/opt/lib/python2.5/random.py", line 58, in <module>
SG_MAGICCONST = 1.0 + _log(4.5)
OverflowError: math range error
我不知道這些錯誤的意思;我搜索了一些沒有成功。上面的腳本是爲電影下載字幕的較大腳本的一部分(我剛從較大的腳本中取出錯誤部分並在此處發佈)。
我寫到這個腳本運行在Synology DS213j上,因爲我認爲這可能是python安裝的問題。一般來說,我在爲我的synylogy安裝ipkg
時遇到了問題。我結束了this教程。從教程安裝引導程序後,我只運行ipkg install python
並且程序包已成功安裝。我的Python版本是Python 2.5.6
。
感謝
嗨,運行'哪個python'我有'/ opt/bin/python'。 –
你的蟒蛇壞了。嘗試從shell運行命令,通過$ python進入python並運行命令。 – 0x90
是的,那是2.5 python的東西。我剛安裝了2.7,urlopen工作正常。感謝您的幫助:) –