我刚刚购买了synology (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时遇到了问题。最后我学习了这教程。在安装了教程中的引导程序之后,我只运行了ipkg install python并成功地安装了软件包。我的python版本是Python 2.5.6。
谢谢
发布于 2014-05-17 13:46:35
问题是在#!/opt/bin/python中,运行which python以找出您的python二进制完整路径是什么。
如您所见,您的are ok列表如下:
>>> 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>我认为应该使用python2.7或关注
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.7使用ipkg
ipkg update
ipkg install python27python2.7将启动python解释器。
https://stackoverflow.com/questions/23711905
复制相似问题