:param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.
:param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
:param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
- :param store_cookies: (optional) if ``False``, the received cookies as part of the HTTP response would be ignored.
:param files: (optional) Dictionary of 'name': file-like-objects (or {'name': ('filename', fileobj)}) for multipart encoding upload.
:param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
:param timeout: (optional) Float describing the timeout of the request.
:param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
:param return_response: (optional) If False, an un-sent Request object will returned.
:param session: (optional) A :class:`Session` object to be used for the request.
- :param config: (optional) A configuration dictionary.
+ :param config: (optional) A configuration dictionary. See ``request.defaults`` for allowed keys and their default values.
:param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided.
:param prefetch: (optional) if ``True``, the response content will be immediately downloaded.
:param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.
:pool_connections: The number of active HTTP connection pools to use.
:encode_uri: If true, URIs will automatically be percent-encoded.
:trust_env: If true, the surrouding environment will be trusted (environ, netrc).
+:param store_cookies: If false, the received cookies as part of the HTTP response would be ignored.
"""
defaults['keep_alive'] = True
defaults['encode_uri'] = True
defaults['trust_env'] = True
+defaults['store_cookies'] = True
params=dict(),
auth=None,
cookies=None,
- store_cookies=True,
timeout=None,
redirect=False,
allow_redirects=False,
# Dictionary mapping protocol to the URL of the proxy (e.g. {'http': 'foo.bar:3128'})
self.proxies = dict(proxies or [])
- #param store_cookies: (optional) if ``False``, the received cookies as part of the HTTP response would be ignored.
- self.store_cookies = store_cookies
-
# If no proxies are given, allow configuration by environment variables
# HTTP_PROXY and HTTPS_PROXY.
if not self.proxies and self.config.get('trust_env'):
response.encoding = get_encoding_from_headers(response.headers)
# Add new cookies from the server. Don't if configured not to
- if self.store_cookies:
+ if self.config.get('store_cookies'):
extract_cookies_to_jar(self.cookies, self, resp)
# Save cookies in Response.
def __init__(self,
headers=None,
cookies=None,
- store_cookies=True,
auth=None,
timeout=None,
proxies=None,
self.prefetch = prefetch
self.verify = verify
self.cert = cert
- self.store_cookies = store_cookies
for (k, v) in list(defaults.items()):
self.config.setdefault(k, deepcopy(v))
data=None,
headers=None,
cookies=None,
- store_cookies=True,
files=None,
auth=None,
timeout=None,
:param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.
:param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
:param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
- :param store_cookies: (optional) if ``False``, the received cookies as part of the HTTP response would be ignored.
:param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.
:param auth: (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth.
:param timeout: (optional) Float describing the timeout of the request.
:param allow_redirects: (optional) Boolean. Set to True by default.
:param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
:param return_response: (optional) If False, an un-sent Request object will returned.
- :param config: (optional) A configuration dictionary.
+ :param config: (optional) A configuration dictionary. See ``request.defaults`` for allowed keys and their default values.
:param prefetch: (optional) if ``True``, the response content will be immediately downloaded.
:param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided.
:param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.
params=params,
headers=headers,
cookies=cookies,
- store_cookies=store_cookies,
files=files,
auth=auth,
hooks=hooks,
def test_disabled_cookie_persistence(self):
"""Test that cookies are not persisted when configured accordingly."""
+ config = {'store_cookies' : False}
+
# Check the case when no cookie is passed as part of the request and the one in response is ignored
- cookies = requests.get(httpbin('cookies', 'set', 'key', 'value'), store_cookies = False).cookies
- self.assertEqual(cookies.get("key"), None)
+ cookies = requests.get(httpbin('cookies', 'set', 'key', 'value'), config = config).cookies
+ self.assertIsNone(cookies.get("key"))
# Test that the cookies passed while making the request still gets used and is available in response object.
# only the ones received from server is not saved
- cookies_2 = requests.get(httpbin('cookies', 'set', 'key', 'value'), store_cookies = False,\
+ cookies_2 = requests.get(httpbin('cookies', 'set', 'key', 'value'), config = config,\
cookies = {"key_2" : "value_2"}).cookies
self.assertEqual(len(cookies_2), 1)
self.assertEqual(cookies_2.get("key_2"), "value_2")
# Use the session and make sure that the received cookie is not used in subsequent calls
s = requests.session()
- s.get(httpbin('cookies', 'set', 'key', 'value'), store_cookies = False)
+ s.get(httpbin('cookies', 'set', 'key', 'value'), config = config)
r = s.get(httpbin('cookies'))
self.assertEqual(json.loads(r.text)['cookies'], {})