diff options
author | Christopher Baines <mail@cbaines.net> | 2015-12-22 13:46:21 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2015-12-22 13:46:21 +0000 |
commit | 1f19c06843e6d266368e3b570352bdf7d789a0de (patch) | |
tree | 042bc99c162d671c2b2fb7cc5cb4400ef26c1bed /requests/api.py | |
parent | cb40ec082506c0d9eb05978839bed2f12541af35 (diff) | |
download | python-requests-upstream.tar python-requests-upstream.tar.gz |
Import requests_2.9.1.orig.tar.gzupstream/2.9.1upstream
Diffstat (limited to 'requests/api.py')
-rw-r--r-- | requests/api.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/requests/api.py b/requests/api.py index 72a777b..b21a1a4 100644 --- a/requests/api.py +++ b/requests/api.py @@ -33,7 +33,7 @@ def request(method, url, **kwargs): :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed. :type allow_redirects: bool :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy. - :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided. + :param verify: (optional) whether the SSL cert will be verified. A CA_BUNDLE path can also be provided. Defaults to ``True``. :param stream: (optional) if ``False``, the response content will be immediately downloaded. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. :return: :class:`Response <Response>` object @@ -46,13 +46,11 @@ def request(method, url, **kwargs): <Response [200]> """ - session = sessions.Session() - response = session.request(method=method, url=url, **kwargs) - # By explicitly closing the session, we avoid leaving sockets open which - # can trigger a ResourceWarning in some cases, and look like a memory leak - # in others. - session.close() - return response + # By using the 'with' statement we are sure the session is closed, thus we + # avoid leaving sockets open which can trigger a ResourceWarning in some + # cases, and look like a memory leak in others. + with sessions.Session() as session: + return session.request(method=method, url=url, **kwargs) def get(url, params=None, **kwargs): |