class documentation

class RequestsCookieJar(cookielib.CookieJar, MutableMapping):

View In Hierarchy

Compatibility class; is a cookielib.CookieJar, but exposes a dict interface.

This is the CookieJar we create by default for requests and sessions that don't specify one, since some clients may expect response.cookies and session.cookies to support dict operations.

Requests does not use the dict interface internally; it's just for compatibility with external client code. All requests code should work out of the box with externally provided instances of CookieJar, e.g. LWPCookieJar and FileCookieJar.

Unlike a regular CookieJar, this class is pickleable.

Warning

dictionary operations that are normally O(1) may be O(n).

Method copy Return a copy of this RequestsCookieJar.
Method get Dict-like get() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains.
Method get​_dict Takes as an argument an optional domain and path and returns a plain old Python dict of name-value pairs of cookies that meet the requirements.
Method get​_policy Return the CookiePolicy instance used.
Method items Dict-like items() that returns a list of name-value tuples from the jar. Allows client-code to call dict(RequestsCookieJar) and get a vanilla python dict of key value pairs.
Method iteritems Dict-like iteritems() that returns an iterator of name-value tuples from the jar.
Method iterkeys Dict-like iterkeys() that returns an iterator of names of cookies from the jar.
Method itervalues Dict-like itervalues() that returns an iterator of values of cookies from the jar.
Method keys Dict-like keys() that returns a list of names of cookies from the jar.
Method list​_domains Utility method to list all the domains in the jar.
Method list​_paths Utility method to list all the paths in the jar.
Method multiple​_domains Returns True if there are multiple domains in the jar. Returns False otherwise.
Method set Dict-like set() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains.
Method set​_cookie Undocumented
Method update Updates this jar with cookies from another CookieJar or dict-like
Method values Dict-like values() that returns a list of values of cookies from the jar.
Method __contains__ Undocumented
Method __delitem__ Deletes a cookie given a name. Wraps cookielib.CookieJar's remove_cookie_by_name().
Method __getitem__ Dict-like __getitem__() for compatibility with client code. Throws exception if there are more than one cookie with name. In that case, use the more explicit get() method instead.
Method __getstate__ Unlike a normal CookieJar, this class is pickleable.
Method __setitem__ Dict-like __setitem__ for compatibility with client code. Throws exception if there is already a cookie of that name in the jar. In that case, use the more explicit set() method instead.
Method __setstate__ Unlike a normal CookieJar, this class is pickleable.
Method ​_find Requests uses this method internally to get cookie values.
Method ​_find​_no​_duplicates Both __get_item__ and get call this function: it's never used elsewhere in Requests.
Instance Variable ​_cookies​_lock Undocumented
def copy(self):
Return a copy of this RequestsCookieJar.
def get(self, name, default=None, domain=None, path=None):

Dict-like get() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains.

Warning

operation is O(n), not O(1).

def get_dict(self, domain=None, path=None):
Takes as an argument an optional domain and path and returns a plain old Python dict of name-value pairs of cookies that meet the requirements.
Returns
dictUndocumented
def get_policy(self):
Return the CookiePolicy instance used.
def items(self):

Dict-like items() that returns a list of name-value tuples from the jar. Allows client-code to call dict(RequestsCookieJar) and get a vanilla python dict of key value pairs.

See Also

keys() and values().

def iteritems(self):

Dict-like iteritems() that returns an iterator of name-value tuples from the jar.

See Also

iterkeys() and itervalues().

def iterkeys(self):

Dict-like iterkeys() that returns an iterator of names of cookies from the jar.

See Also

itervalues() and iteritems().

def itervalues(self):

Dict-like itervalues() that returns an iterator of values of cookies from the jar.

See Also

iterkeys() and iteritems().

def keys(self):

Dict-like keys() that returns a list of names of cookies from the jar.

See Also

values() and items().

def list_domains(self):
Utility method to list all the domains in the jar.
def list_paths(self):
Utility method to list all the paths in the jar.
def multiple_domains(self):
Returns True if there are multiple domains in the jar. Returns False otherwise.
Returns
boolUndocumented
def set(self, name, value, **kwargs):
Dict-like set() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains.
def set_cookie(self, cookie, *args, **kwargs):

Undocumented

def update(self, other):
Updates this jar with cookies from another CookieJar or dict-like
def values(self):

Dict-like values() that returns a list of values of cookies from the jar.

See Also

keys() and items().

def __contains__(self, name):

Undocumented

def __delitem__(self, name):
Deletes a cookie given a name. Wraps cookielib.CookieJar's remove_cookie_by_name().
def __getitem__(self, name):

Dict-like __getitem__() for compatibility with client code. Throws exception if there are more than one cookie with name. In that case, use the more explicit get() method instead.

Warning

operation is O(n), not O(1).

def __getstate__(self):
Unlike a normal CookieJar, this class is pickleable.
def __setitem__(self, name, value):
Dict-like __setitem__ for compatibility with client code. Throws exception if there is already a cookie of that name in the jar. In that case, use the more explicit set() method instead.
def __setstate__(self, state):
Unlike a normal CookieJar, this class is pickleable.
def _find(self, name, domain=None, path=None):

Requests uses this method internally to get cookie values.

If there are conflicting cookies, _find arbitrarily chooses one. See _find_no_duplicates if you want an exception thrown if there are conflicting cookies.

Parameters
namea string containing name of cookie
domain(optional) string containing domain of cookie
path(optional) string containing path of cookie
Returns
cookie.value
def _find_no_duplicates(self, name, domain=None, path=None):
Both __get_item__ and get call this function: it's never used elsewhere in Requests.
Parameters
namea string containing name of cookie
domain(optional) string containing domain of cookie
path(optional) string containing path of cookie
Returns
cookie.value
Raises
KeyErrorif cookie is not found
CookieConflictErrorif there are multiple cookies that match name and optionally domain and path
_cookies_lock =

Undocumented