Basically, I have a url that I'm hitting to get some XML data. The endpoint I cannot disclose, but doing:
curl -v "http://my-url.com/some/endpoint"
returns a 200 OK and the content pretty much instantly.
Using the requests module by Kenneth Reitz, I have both a POST request and a GET request that both take 30 seconds to return content.
If I use it this way:
from timeit import Timer
t = Timer(lambda: requests.get(myurl).content)
print t.timeit(number=1)
30.2136261463
it takes 30.2 sec on average each time. Same with my POST request. If I don't ask for content and just the status_code response, I get the same situation, unless if I pass the stream=True, where I get the response quickly, but not the content.
My confusion is within the curl command... I get both the response and content in under 10ms. I tried faking the user-agent in my python test, tried passing numerous arguments to the get() function etc. There must be some major difference between how curl and python-requests do requests that I am not aware of. I am a newbie, so I do apologise if I am missing something obvious.
I would also like to mention that I have tried multiple machines for this, multiple version of curl, python and even tried some REST clients like Postman etc. Only curl performs lightning fast - hitting the same endpoint in every case BTW. I understand one of the options is to do a subprocess call to curl within my test, but... Is that a good idea?
EDIT: I care about the content. I am aware I can get the response code quickly (headers).
Thanks in advance,
Tihomir.
UPDATE:
I am now using pycurl2 in my test, so this is just a workaround as I was hoping I could use python-requests for everything. Still curious as to why is curl so much faster.