Is urllib2 slower than requests in python3

I use python to just call api.github.gist. I first tried urllib2, which cost me about 10 seconds !. Requests accept less than 1 senond

I work in a collaboration network using proxies. Do these two libraries have different default proxy behaviors?

And I use a violinist to check the network. In both situations, the HTTP request completed in about 40 ms. So where is urllib spending time?

+4
source share
1 answer

Most likely, DNS caching has accelerated requests. DNS queries can take a lot of time on corporate networks, I don’t know why, but I experience the same thing. The first time you sent a query with urllib2DNS requested, slow and cached. The second time you sent a request using requests, DNS does not need to be requested, just retrieved from the cache.

Clear the DNS cache and reorder, i.e. request from the requestsfirst, see if there is any difference.

0
source

Source: https://habr.com/ru/post/1626961/


All Articles