mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
Issue #12955: Change the urlopen() examples to use context managers where appropriate.
Patch by Martin Panter.
This commit is contained in:
parent
8ad751e024
commit
9575e1891f
5 changed files with 38 additions and 28 deletions
|
|
@ -687,7 +687,8 @@ Yes. Here's a simple example that uses urllib.request::
|
|||
### connect and send the server a path
|
||||
req = urllib.request.urlopen('http://www.some-server.out-there'
|
||||
'/cgi-bin/some-cgi-script', data=qs)
|
||||
msg, hdrs = req.read(), req.info()
|
||||
with req:
|
||||
msg, hdrs = req.read(), req.info()
|
||||
|
||||
Note that in general for percent-encoded POST operations, query strings must be
|
||||
quoted using :func:`urllib.parse.urlencode`. For example, to send
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue