You are here : python_3requestsrencoding

r.encoding - requests

When you make a request, Requests makes educated guesses about the encoding of the response based on the HTTP headers. The text encoding guessed by Requests is used when you access r.text. You can find out what encoding Requests is using, and change it, using the r.encoding property.

If you change the encoding, Requests will use the new value of r.encoding whenever you call r.text. 


Syntax

#to view encoding
r.encoding
#to change encoding
r.encoding = 'ISO-8859-1'


Example

import requests
r=requests.get('http://example.com')
print(r.encoding)		#displays encoding set by default
r.encoding = 'ISO-8859-1'	#change encoding


Output / Return Value


Limitations


Alternatives / See Also


Reference