[Python-checkins] cpython (merge 3.5 -> default): Issue #25570: Merge add_header() example from 3.5

martin.panter python-checkins at python.org
Wed Jun 1 04:29:42 EDT 2016


https://hg.python.org/cpython/rev/75dc64c8c22b
changeset:   101582:75dc64c8c22b
parent:      101580:b75b4fdd62f8
parent:      101581:320b9a65ac07
user:        Martin Panter <vadmium+py at gmail.com>
date:        Wed Jun 01 08:17:27 2016 +0000
summary:
  Issue #25570: Merge add_header() example from 3.5

files:
  Doc/library/urllib.request.rst |  7 ++++++-
  1 files changed, 6 insertions(+), 1 deletions(-)


diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst
--- a/Doc/library/urllib.request.rst
+++ b/Doc/library/urllib.request.rst
@@ -189,7 +189,7 @@
 
    *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 @@
 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 @@
    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

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list