I am using requests library of python and making a request like this
r = requests.get(solrShard1, params = solrParams)
Now i want to get the exact url the requests library is creating . I have tried using
req = requests.Request('POST',solrShard1, params = solrParams)
prepared = req.prepare()
print >>sys.stderr, "REQUEST START"
print >>sys.stderr, req.url
print >>sys.stderr, "REQUEST END"
but it only prints the url and not the exact url along with parameters and everything . How can i get the exact URL
You are showing the url from request object, instead of the prepared object.
The call to the prepare
method doesn't mutate the object itself, instead it returns the prepared object, which you are already assigning to the prepared
variable, but you are not using it anywhere.
Just change your code for the following and it should work:
print >>sys.stderr, "REQUEST START"
print >>sys.stderr, prepared.url
print >>sys.stderr, "REQUEST END"
I tried the code below and it works fine for me:
req = requests.Request('POST', 'http://google.com', params={'param1': 10})
prep = req.prepare()
print(prep.url)
>> 'http://google.com/?param1=10'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With