4

I use python to simply call api.github.gist. I have tried urllib2 at first which cost me about 10 seconds!. The requests takes less than 1 senond

I am under a cooperation network, using a proxy. Do these two libs have different default behavior under a proxy?

And I use fiddler to check the network. In both situation, the http request finished in about 40ms. So where urllib spends the time on?

templefox
  • 475
  • 1
  • 5
  • 17

1 Answers1

0

It's most likely that DNS caching sped up the requests. DNS queries might take a lot of time in corporate networks, don't know why but I experience the same. The first time you sent the request with urllib2 DNS queried, slow, and cached. The second time you sent the request with requests, DNS needed not to be queried just retrieved from the cache.

Clear up the DNS cache and change the order, i.e. request with requests first, see if there is any difference.

mehmetminanc
  • 1,359
  • 9
  • 14