我试过这个,
>>> 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>
答案 0 :(得分:4)
可以访问或不访问双重检查域。
目前我在域名tycho.usno.navy.mil上收到504网关超时错误。
看起来该网站已经关闭,而且还有一个非常简单的说法
不仅仅是你! http://tycho.usno.navy.mil向下看 从这里开始。
这就是getaddrinfo
失败的原因
答案 1 :(得分:0)
包装在try..except中可以帮助保持整洁:
try:
urllib2.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl')
except URLError:
print "Error opening URL"