我刚买了synology NAS(DS213J),我正在尝试运行python脚本。
我的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安装的东西。通常我在为我的同义词安装ipkg
时遇到问题。我最后得到了this教程。从教程安装bootstrap后,我只运行ipkg install python
并成功安装了包。我的python版本是Python 2.5.6
。
由于
答案 0 :(得分:1)
问题出在#!/opt/bin/python
,运行which python
以确定你的python二进制完整路径是什么。
你可以看到你的清单是好的:
>>> import urllib
>>> response = urllib.urlopen('http://google.com')
>>> html = response.read()
>>> print html
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="iw" dir="rtl"><head><meta content="/images/google_favicon_128.png" itemprop="image"><title>Google</title>[...]</body></html>
我认为你应该使用python 2.7 或follow
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.7
使用ipkg
:
ipkg update
ipkg install python27
python2.7
将启动python解释器。