summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-06-01 08:20:22 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-06-01 08:20:22 (GMT)
commitfcd7d34afb644a936496a0499a9f5d533bd0da83 (patch)
tree217858084faaeece8ddff94a1e98de8f05a78c1d /Doc
parentd2b4926fa7c3d9d789702221e63d9fdf57647f1e (diff)
downloadcpython-fcd7d34afb644a936496a0499a9f5d533bd0da83.zip
cpython-fcd7d34afb644a936496a0499a9f5d533bd0da83.tar.gz
cpython-fcd7d34afb644a936496a0499a9f5d533bd0da83.tar.bz2
Issue #25570: Add example of customizing User-Agent via add_header()
Diffstat (limited to 'Doc')
-rw-r--r--Doc/howto/urllib2.rst2
-rw-r--r--Doc/library/urllib2.rst7
2 files changed, 8 insertions, 1 deletions
diff --git a/Doc/howto/urllib2.rst b/Doc/howto/urllib2.rst
index ff2e7a8..6bb06d4 100644
--- a/Doc/howto/urllib2.rst
+++ b/Doc/howto/urllib2.rst
@@ -1,3 +1,5 @@
+.. _urllib-howto:
+
************************************************
HOWTO Fetch Internet Resources Using urllib2
************************************************
diff --git a/Doc/library/urllib2.rst b/Doc/library/urllib2.rst
index 735694e..8a4c80e 100644
--- a/Doc/library/urllib2.rst
+++ b/Doc/library/urllib2.rst
@@ -167,7 +167,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 used by a browser to identify itself --
+ 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
(X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11"``, while :mod:`urllib2`'s
@@ -950,6 +950,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 100 bytes of
it::
@@ -1016,6 +1019,8 @@ Use the *headers* argument to the :class:`Request` constructor, or::
import urllib2
req = urllib2.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 = urllib2.urlopen(req)
:class:`OpenerDirector` automatically adds a :mailheader:`User-Agent` header to