繁体   English   中英

Python urlopen错误

[英]Python urlopen error

我刚刚购买了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遇到问题。 我结束了教程。 从教程安装引导程序后,我只运行ipkg install python并成功ipkg install python软件包。 我的python版本是Python 2.5.6

谢谢

问题出在#!/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遵循

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

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错误”怎么办? python urlopen 错误 [Errno 10060] 网页保存的Python urlopen错误 Python urlopen连接中止 - urlopen错误[Errno 10053] Python 3.5中的Request,urlopen中的禁止(403)错误 Python 网页抓取错误 403 + urlopen 解码问题 学习 python 时的障碍 - Urlopen 错误 10060 如何处理python搜寻器的urlopen错误? 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:urllib urlopen 卡住,超时错误
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM