Search code examples
pythonhttppycurl

Is there a way to get the full http request in pycurl?


c = pycurl.Curl()
c.setopt(c.URL, 'https://httpbin.org/post')

post_data = {'field': 'value'}
# Form data must be provided already urlencoded.
postfields = urlencode(post_data)
# Sets request method to POST,
# Content-Type header to application/x-www-form-urlencoded
# and data to send in request body.
c.setopt(c.POSTFIELDS, postfields)

c.perform()
c.close()

This is example from official doc. I want to know what would be the http request looks like. Is there a way to do that?


Solution

  • You could use the VERBOSE option, works like curl -v, will print request/response headers to stderr:

    c.setopt(pycurl.VERBOSE, 1)
    

    see more detail on pycurl doc.