June 2015
Intermediate to advanced
320 pages
7h 18m
English
To make use of the functionality that headers provide, we add headers to a request before sending it. To do this, we can't just use urlopen(). We need to follow these steps:
Request objecturlopen() to send the request objectWe're going to learn how to customize a request for retrieving a Swedish 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. Note that not all servers hold versions of resources in multiple languages, so not all servers will respond to Accept-LanguageLinux home page.
First, we create a Request object:
>>> from urllib.request import Request >>> req = Request('http://www.debian.org') ...
Read now
Unlock full access