Skip to content

[Bug]: Cannot unpickle CookieJar #35

@danielVebman

Description

@danielVebman

TLS Requests version

v1.1.3

Issue description

When unpickling a Response, NameError: name 'threading' is not defined gets thrown in RequestsCookieJar.__setstate__. I fixed this by importing threading in __setstate__:

def __setstate__(self, state):
    """Unlike a normal CookieJar, this class is pickleable."""
    self.__dict__.update(state)
    if "_cookies_lock" not in self.__dict__:
        import threading
        self._cookies_lock = threading.RLock()

Steps to reproduce / Code Sample

import tls_requests, pickle
resp = tls_requests.get('https://google.com')
resp.stream = None # remove so we can pickle resp
path = ...
with open(path, 'wb') as f:
    pickle.dump(resp, f)
with open(path, 'rb') as f:
    pickle.load(f) # raises: NameError: name 'threading' is not defined

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions