[Python] How to print text of POST request without making request

Discussão em 'Python' iniciado por Stack, Junho 17, 2025.

  1. Stack

    Stack Membro Participativo

    If I make the request

    api-key = 'asdfklhsdfkjahsdlgkjahlkdjahfsa'
    url = 'https://www.website.com'

    headers = {'api-key': api-key,
    'Content-Type': 'application/json'}

    request_data = {'foo': 'bar', 'egg': 'spam'}

    result = requests.post(url, headers=headers, data=request_data)


    The server is contacted. Suppose that instead I want to do something like

    request_string = requests.foobar(url, headers=headers, data=request_data)
    import os
    os.system('curl ' + request_string)


    So that I can look to see what the request is doing without bothering the server (possibly to the point that I could c&p it into curl), what would foobar be? Or in general, what is a way to inspect the contents of the request without making it?

    Continue reading...

Compartilhe esta Página