2010-05-12 85 views
2

我試圖運行此,在Python,urllib2的給錯誤

>>> urllib2.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') 

但它給這樣的錯誤,誰能告訴我一個解決方案嗎?

Traceback (most recent call last): 
    File "<pyshell#11>", line 1, in <module> 
    urllib2.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') 
    File "C:\Python26\lib\urllib2.py", line 126, in urlopen 
    return _opener.open(url, data, timeout) 
    File "C:\Python26\lib\urllib2.py", line 391, in open 
    response = self._open(req, data) 
    File "C:\Python26\lib\urllib2.py", line 409, in _open 
    '_open', req) 
    File "C:\Python26\lib\urllib2.py", line 369, in _call_chain 
    result = func(*args) 
    File "C:\Python26\lib\urllib2.py", line 1161, in http_open 
    return self.do_open(httplib.HTTPConnection, req) 
    File "C:\Python26\lib\urllib2.py", line 1136, in do_open 
    raise URLError(err) 
URLError: <urlopen error [Errno 11001] getaddrinfo failed> 

回答

4

雙重檢查域是否可訪問。

我在這裏爲域名tycho.usno.navy.mil得到504網關超時錯誤,此刻。

貌似網站已關閉,也downforeveryoneorjustme.com說

這不只是你! http://tycho.usno.navy.mil從這裏看不到 。

這就是爲什麼getaddrinfo失敗

+2

從地球附近一處祕密地點確認。 – msw 2010-05-12 11:41:26

0

包裝在try..except可以幫助保持整潔:

try: 
    urllib2.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') 
except URLError: 
    print "Error opening URL"