简体   繁体   English

Python urlopen错误

[英]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解释器。

Python:网址错误: <urlopen error [errno 10060]< div><div id="text_translate"><p> <strong>操作系统:Windows 7;</strong> <strong>Python 2.7.3 使用 Python GUI Shell</strong></p><p> 我正在尝试通过 Python 阅读一个网站,并且有几个作者使用urllib和urllib2库。 为了将站点存储在变量中,我看到了一种类似的方法:</p><pre> import urllib import urllib2 g = "http://www.google.com/" read = urllib2.urlopen(g)</pre><p> 最后一行在 120 多秒后生成错误:</p><pre> > Traceback (most recent call last): File "<pyshell#27>", line 1, in > <module> > r = urllib2.urlopen(o) File "C:\Python27\lib\urllib2.py", line 126, in urlopen > return _opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 400, in open > response = self._open(req, data) File "C:\Python27\lib\urllib2.py", line 418, in _open > '_open', req) File "C:\Python27\lib\urllib2.py", line 378, in _call_chain > result = func(*args) File "C:\Python27\lib\urllib2.py", line 1207, in http_open > return self.do_open(httplib.HTTPConnection, req) File "C:\Python27\lib\urllib2.py", line 1177, in do_open > raise URLError(err) URLError: <urlopen error [Errno 10060] A connection attempt failed because the connected party did not properly > respond after a period of time, or established connection failed > because connected host has failed to respond></pre><p> 我尝试绕过g变量并尝试urlopen("http://www.google.com/")也没有成功(它在相同的时间长度后生成相同的错误)。</p></div></urlopen> - Python: URLError: <urlopen error [Errno 10060]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python中的“ urlopen错误”怎么办? - What to do with “urlopen error” in python? python urlopen 错误 [Errno 10060] - python urlopen error [Errno 10060] 网页保存的Python urlopen错误 - Python urlopen error with saved webpage Python urlopen连接中止 - urlopen错误[Errno 10053] - Python urlopen connection aborted - urlopen error [Errno 10053] Python 3.5中的Request,urlopen中的禁止(403)错误 - Forbidden (403) error in Request,urlopen in Python 3.5 Python 网页抓取错误 403 + urlopen 解码问题 - Python webscraping error 403 + urlopen decode problem 学习 python 时的障碍 - Urlopen 错误 10060 - Roadblock while learning python - Urlopen error 10060 如何处理python搜寻器的urlopen错误? - how to handle python crawler's urlopen error? Python:网址错误: <urlopen error [errno 10060]< div><div id="text_translate"><p> <strong>操作系统:Windows 7;</strong> <strong>Python 2.7.3 使用 Python GUI Shell</strong></p><p> 我正在尝试通过 Python 阅读一个网站,并且有几个作者使用urllib和urllib2库。 为了将站点存储在变量中,我看到了一种类似的方法:</p><pre> import urllib import urllib2 g = "http://www.google.com/" read = urllib2.urlopen(g)</pre><p> 最后一行在 120 多秒后生成错误:</p><pre> > Traceback (most recent call last): File "<pyshell#27>", line 1, in > <module> > r = urllib2.urlopen(o) File "C:\Python27\lib\urllib2.py", line 126, in urlopen > return _opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 400, in open > response = self._open(req, data) File "C:\Python27\lib\urllib2.py", line 418, in _open > '_open', req) File "C:\Python27\lib\urllib2.py", line 378, in _call_chain > result = func(*args) File "C:\Python27\lib\urllib2.py", line 1207, in http_open > return self.do_open(httplib.HTTPConnection, req) File "C:\Python27\lib\urllib2.py", line 1177, in do_open > raise URLError(err) URLError: <urlopen error [Errno 10060] A connection attempt failed because the connected party did not properly > respond after a period of time, or established connection failed > because connected host has failed to respond></pre><p> 我尝试绕过g变量并尝试urlopen("http://www.google.com/")也没有成功(它在相同的时间长度后生成相同的错误)。</p></div></urlopen> - Python: URLError: <urlopen error [Errno 10060] Python:urllib urlopen 卡住,超时错误 - Python: urllib urlopen stuck, timeout error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM