1

hope you can help me on with this issue that i've been trying to solve within the last 2 weeks and i finallly gave up on reading the requests documentation. I happen to think that what i need is very simple, but somehow i have not been able to solve it.

I have the following code:

import requests

a=requests.post(url, params)

How do i know the http string that im sending?

What i need to do is to get the string so I can make a signature with a secret key, add it to the parameters and make the post with the signature as a new parameter. So, i know the methods and the paremeters in order to post, but I dont know that the request.post makes to those objects. It would be something like this:

what_i_send=request.post(url, params)
signature=signature_method(what_i_send)
params["signature"]=signature
final_request=request.post(url,params)

thanks a lot!

  • You mean you need to dump the HTTP request? – Gustavo Kawamoto Oct 07 '20 at 21:02
  • I dont know if that's the name of the method that im looking for, probably yes. What i need this for is to make a signature with the code that im sending so i can add it as a parameter in the final post that im sending. – Gustavo Zárate Oct 07 '20 at 21:19

1 Answers1

0

You can use this answer's neat function and print something like this:

def print_request(req):
    print('{}\r\n{}\r\n\r\n{}'.format(
        req.method + ' ' + req.url,
        '\r\n'.join('{}: {}'.format(k, v) for k, v in req.headers.items()),
        req.body,
    ))

a = requests.post(url, params)
print_request(a.request)
Gustavo Kawamoto
  • 2,665
  • 18
  • 27