[英]Python urlopen error
I've just bought synology NAS (DS213J) and I am trying to run a python script on it. 我刚刚购买了synology NAS(DS213J),并且尝试在其上运行python脚本。
My python script: 我的python脚本:
1 #!/opt/bin/python
2
3 import urllib
4 response = urllib.urlopen('http://google.com')
5 html = response.read()
6 print html
when I run this script, I've got this output : 当我运行此脚本时,我得到以下输出 :
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
I also tried use urllib2 with no success. 我也尝试使用urllib2,但没有成功。
Script: 脚本:
1 #!/opt/bin/python
2
3 import urllib2
4 response = urllib2.urlopen('http://google.com')
5 html = response.read()
6 print html
console output : 控制台输出 :
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
I have no idea what these errors mean; 我不知道这些错误是什么意思。 I've googled some with no success.
我用谷歌搜索没有成功。 The script above is part of a larger script to download subtitles for movies (I've just took error part from the bigger script and posted here).
上面的脚本是一个较大的脚本的一部分,该脚本可以下载电影字幕(我刚刚从较大的脚本中提取了一部分错误,并在此处发布了该脚本)。
I wrote that this script is running on synology DS213j, because I think that may be something with python installation. 我写道该脚本正在synology DS213j上运行,因为我认为这可能与python安装有关。 Generally I had problem with installing
ipkg
for my synylogy. 通常,对于我的协同系统,我在安装
ipkg
遇到问题。 I ended up with this tutorial. 我结束了本教程。 After installing bootstrap from the tutorial, I just run
ipkg install python
and package was installed successfully. 从教程安装引导程序后,我只运行
ipkg install python
并成功ipkg install python
软件包。 My python version is Python 2.5.6
. 我的python版本是
Python 2.5.6
。
Thanks 谢谢
The problem is in #!/opt/bin/python
, run which python
in order to figure out what is your python binary full path is. 问题出在
#!/opt/bin/python
,运行which python
以弄清楚您的python二进制完整路径是什么。
As you can see your list of 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>
I think you should use python 2.7 or follow 我认为您应该使用python 2.7或遵循
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.7
Using ipkg
: 使用
ipkg
:
ipkg update
ipkg install python27
python2.7
will start the python interpreter. python2.7
将启动python解释器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.