Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7aaaded8
Commit
7aaaded8
authored
Jun 01, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #25570: Add example of customizing User-Agent via add_header()
parent
f9aff925
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
1 deletion
+6
-1
Doc/library/urllib.request.rst
Doc/library/urllib.request.rst
+6
-1
No files found.
Doc/library/urllib.request.rst
View file @
7aaaded8
...
...
@@ -189,7 +189,7 @@ The following classes are provided:
*headers* should be a dictionary, and will be treated as if
:meth:`add_header` was called with each key and value as arguments.
This is often used to "spoof" the ``User-Agent`` header, which is
This is often used to "spoof" the ``User-Agent`` header
value
, which is
used by a browser to identify itself -- some HTTP servers only
allow requests coming from common browsers as opposed to scripts.
For example, Mozilla Firefox may identify itself as ``"Mozilla/5.0
...
...
@@ -1111,6 +1111,9 @@ HTTPErrorProcessor Objects
Examples
--------
In addition to the examples below, more examples are given in
:ref:`urllib-howto`.
This example gets the python.org main page and displays the first 300 bytes of
it. ::
...
...
@@ -1220,6 +1223,8 @@ Use the *headers* argument to the :class:`Request` constructor, or::
import urllib.request
req = urllib.request.Request('http://www.example.com/')
req.add_header('Referer', 'http://www.python.org/')
# Customize the default User-Agent header value:
req.add_header('User-Agent', 'urllib-example/0.1 (Contact: . . .)')
r = urllib.request.urlopen(req)
:class:`OpenerDirector` automatically adds a :mailheader:`User-Agent` header to
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment