summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-06-01 08:17:27 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-06-01 08:17:27 (GMT)
commitf9de40666c04ffe3213632f865a1cb05c3c09278 (patch)
tree6885d9070d3c56cac82c49cc00c9d25e1dae39c6
parentd6ce44c4127790c4a98e2cd0dc7443f53fa678e1 (diff)
parent7aaaded8f4bba7fb82f21dc89ca39603c9d6126b (diff)
downloadcpython-f9de40666c04ffe3213632f865a1cb05c3c09278.zip
cpython-f9de40666c04ffe3213632f865a1cb05c3c09278.tar.gz
cpython-f9de40666c04ffe3213632f865a1cb05c3c09278.tar.bz2
Issue #25570: Merge add_header() example from 3.5
-rw-r--r--Doc/library/urllib.request.rst7
1 files changed, 6 insertions, 1 deletions
diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst
index 22cca99..688f149 100644
--- a/Doc/library/urllib.request.rst
+++ b/Doc/library/urllib.request.rst
@@ -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