urllib2 test fails (2.7, linux)

guandalino guandalino at gmail.com
Wed Jul 21 17:06:55 EDT 2010


On 20 Lug, 21:24, Terry Reedy <tjre... at udel.edu> wrote:

Hi Terry, thanks for your reply.

> > ======================================================================
> > ERROR: test_file (__main__.HandlerTests)
> > ----------------------------------------------------------------------
> > Traceback (most recent call last):
> >    File "test_urllib2.py", line 711, in test_file
> >      h.file_open, Request(url))
[cut]
> You could insert a print to find what url caused a problem.

Output:
file://localhost:80/home/redt/sandbox/2.7/lib/python2.7/test/%40test_29416_tmp
file:///file_does_not_exist.txt
file://127.0.0.1:80/home/home/redt/sandbox/2.7/lib/python2.7/test/@test_29416_tmp
file://somerandomhost.ontheinternet.com/home/home/redt/sandbox/2.7/lib/python2.7/test/@test_29416_tmp

Offending line is the the 4th.

> This is in unittest.py. It says that this test case *should* fail, but
> with a different error (urllib.error.URLError) than the one you got
> (gaierror).
>
> >    File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1269,
> > in file_open
> >      return self.open_local_file(req)
> >    File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1301,
> > in open_local_file
> >      (not port and socket.gethostbyname(host) in self.get_names()):
> > gaierror: [Errno -5] No address associated with hostname
>
> gaierror comes from socket.gethostbyname

When I print the value of the variable 'host' in urllib2.py line 1301
I get this: somerandomhost.ontheinternet.com. This is why
socket.gethostbyname(host) raises gaierror -5, there is no address
associated to somerandomhost.ontheinternet.com. Instead the values
that 'host' takes for the other urls are localhost or 127.0.0.1, both
valid for gethostbyname().

Any hint?

Thanks.



More information about the Python-list mailing list