urllib2 test fails (2.7, linux)

Terry Reedy tjreedy at udel.edu
Wed Jul 21 19:13:21 EDT 2010


On 7/21/2010 5:06 PM, guandalino wrote:
> 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.

Ah. I did not see anything like that in 3.1 test_urllib2. Either I just 
simply missed it, or it is obscured, or it was removed because it causes 
failures;-).

>> 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?

Remove the offending fake url.

If you want to investigate the history of the file, go to
http://svn.python.org/view/python/branches/release27-maint/Lib/test/test_urllib2.py?view=log

If you do not get an answer here, file a bug report. If you can, put
orsenthil,benjamin.peterson,ezio.melotti
on the nosy list, as they are recent committers to this file. Say I said 
to do so if you want. Add tjreedy also so I can see responses and learn too.

-- 
Terry Jan Reedy




More information about the Python-list mailing list