March 2019
Beginner
490 pages
12h 40m
English
To make use of the functionality that headers provide, we add headers to a request before sending it. To do this, we need to follow these steps:
We're going to learn how to customize a request to retrieve a Netherlands version of the Debian home page. We will use the Accept-Language header, which tells the server our preferred language for the resource it returns.
First, we create a Request object:
>>> from urllib.request import Request,urlopen >>> req = Request('http://www.debian.org')
Next, we add the header:
>>> req.add_header('Accept-Language', 'nl')
The add_header() method takes the name of the header ...
Read now
Unlock full access