Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python urllib2.urlopen much slower on Windows 7 when asking for localhost

I'm running some python code for the first time on a Windows 7 machine and noticed that this http request to my localserver is much slower than before:

result = urllib2.urlopen("http://localhost:3000/somepath").read()

This is called repeatedly and each time instead of returning immediately it takes around a second. If I replace localhost with 127.0.0.1, it returns immediately as before (was on Mac OS).

No big deal but was curious as to the cause.

If it's DNS, why is it not being cached?

like image 234
yotam.shacham Avatar asked Nov 13 '22 02:11

yotam.shacham


1 Answers

Per yotam.shacham's comment, this problem can be fixed by uncommenting this line from the Windows hosts file:

127.0.0.1 localhost

On Windows 7, the `hosts file is located at

%SystemRoot%\system32\drivers\etc\hosts

where%SystemRoot% is normally C:\WINDOWS

like image 74
2 revs Avatar answered Dec 29 '22 21:12

2 revs