Skip to content

[Bug]: Cannot unpickle CookieJar #35 #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tls_requests/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
__url__ = "https://github.com/thewebscraping/tls-requests"
__author__ = "Tu Pham"
__author_email__ = "thetwofarm@gmail.com"
__version__ = "1.1.3"
__version__ = "1.1.4"
__license__ = "MIT"
1 change: 1 addition & 0 deletions tls_requests/models/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ 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()

def copy(self):
Expand Down
6 changes: 5 additions & 1 deletion tls_requests/models/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def __init__(
self._is_closed = False
self._next: Optional[Request] = None
self.headers = Headers(headers)
self.stream = None
self.status_code = status_code
self.history = history if isinstance(history, list) else []
self.default_encoding = default_encoding
Expand Down Expand Up @@ -135,6 +134,7 @@ def charset(self) -> Optional[str]:
msg = Message()
msg["content-type"] = self.headers["Content-Type"]
return msg.get_content_charset(failobj=None)
return None

@property
def encoding(self) -> str:
Expand Down Expand Up @@ -228,6 +228,10 @@ def close(self) -> None:
self._is_stream_consumed = True
self.stream.close()

# Fix pickle dump
# Ref: https://github.com/thewebscraping/tls-requests/issues/35
self.stream = None

async def aclose(self) -> None:
return self.close()

Expand Down