In Python urllib2 gives error

I tried to run this,

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

      

But it gives an error like this, can anyone tell me the solution?

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>

      

+2


a source to share


2 answers


Double check domain is available or not.

I'm getting 504 Gateway timeout error here for the domain - tycho.usno.navy.mil, for now.

It looks like the site is down, also downforeveryoneorjustme.com says that



It's not just you! http://tycho.usno.navy.mil looks down from here.

This is why it getaddrinfo

fails

+4


a source


A wrapper in try..except can help keep it neat:



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

      

0


a source







All Articles