簡體   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