Is it possible in Python requests to print entire HTTP request?

0 votes
While using the requests module is there any way to print the raw HTTP request?

I don't want just the headers, I want the request line, headers, and content printout. Is it possible to see what ultimately is constructed from HTTP request?

Thanks!
Nov 26, 2018 in Python by Anirudh
• 2,080 points
4,127 views

1 answer to this question.

0 votes

A better idea is to use the requests_toolbelt library, which can dump out both requests and responses as strings for you to print to the console. It handles all the tricky cases with files and encodings which the above solution does not handle well.

It's as easy as this:

import requests
from requests_toolbelt.utils import dump

resp = requests.get('https://httpbin.org/redirect/5')
data = dump.dump_all(resp)
print(data.decode('utf-8'))
answered Nov 26, 2018 by Nymeria
• 3,540 points

Related Questions In Python

0 votes
1 answer

Is it possible to print all the modules imported in a python script?

Since I am using Python 3.6, I ...READ MORE

answered Jul 3, 2019 in Python by Neel
• 3,010 points
102 views
0 votes
1 answer

Is it possible to print a string and a variable in a single print statement in Python?

This can be done using simple string ...READ MORE

answered Jul 15, 2019 in Python by Neel
• 3,010 points
111 views
0 votes
1 answer

is it possible to do method overloading in python?

You cannot have two methods with the ...READ MORE

answered Mar 25, 2019 in Python by Mohammad
• 3,230 points
74 views
0 votes
1 answer

Is it possible to create an array with all values as zero in python?

You can use  np.zeros(4,3) This will create a 4 ...READ MORE

answered May 24, 2019 in Python by Anjali
128 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,058 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer
0 votes
1 answer

List comprehension on a nested list - How to do it in Python?

Not sure what your desired output is, ...READ MORE

answered Nov 21, 2018 in Python by Nymeria
• 3,540 points
433 views