May 2018
Beginner to intermediate
452 pages
11h 26m
English
The response objects returned from these request functions are not the same as those returned by urlopen(); they contain all the same data, but in a slightly different (and generally more convenient) form.
For example, the response headers are already translated into a Python dict for us, as follows:
>>> r = requests.get('http://www.alandmoore.com')
>>> r.headers
{'Date': 'Thu, 15 Feb 2018 21:13:42 GMT', 'Server': 'Apache',
'Last-Modified': 'Sat, 17 Jun 2017 14:13:49 GMT',
'ETag': '"20c003f-19f7-5945391d"', 'Content-Length': '6647',
'Keep-Alive': 'timeout=15, max=200', 'Connection': 'Keep-Alive',
'Content-Type': 'text/html'}
Another difference is that requests does not automatically raise an exception on HTTP errors. ...