This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: MozillaCookieJar does not handle session cookies
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Ramy Abdel-Azim, jdetrey, orsenthil, piotr.dobrogost, remi.lapeyre
Priority: normal Keywords: patch

Created on 2013-02-08 21:23 by piotr.dobrogost, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
session-cookies.patch jdetrey, 2015-01-07 10:33 patch review
session-cookies-test.patch jdetrey, 2015-01-07 14:11 review
Pull Requests
URL Status Linked Edit
PR 11792 open remi.lapeyre, 2019-02-08 16:36
PR 11792 open remi.lapeyre, 2019-02-08 16:36
PR 11792 open remi.lapeyre, 2019-02-08 16:37
Messages (6)
msg181703 - (view) Author: Piotr Dobrogost (piotr.dobrogost) Date: 2013-02-08 21:23
It seems there's no information on how should session cookies be stored in the Netscape/Mozilla's cookies.txt file with regard to expiry time - see http://www.cookiecentral.com/faq/#3.5 Maybe Netscape has not been saving such cookies at all thus this lack of specification? Nevertheless, both wget and curl use 0 as expiry time to denote session cookies; it works both when reading cookies from file and writing to file. However Python's MozillaCookieJar's class uses empty string for the same purpose which makes it incompatible both with wget and curl - see http://hg.python.org/cpython/file/bd8afb90ebf2/Lib/http/cookiejar.py#l2027

I propose to make a change in implementation of MozillaCookieJar class and treat cookies with 0 set as expiry time as session cookies both when reading from a file and writing to a file.

Motivation for this bug report comes from the following question on Stack Overflow - http://stackoverflow.com/q/14742899/95735
msg182501 - (view) Author: Piotr Dobrogost (piotr.dobrogost) Date: 2013-02-20 13:05
I could try to write a patch with some help if there was any chance it might be accepted. Where do I start?
msg233574 - (view) Author: Jérémie Detrey (jdetrey) * Date: 2015-01-07 10:33
Dear all,

Here is a small tentative patch for fixing this issue.

Expiry times for session cookies are now written as "0", and both "0" and "" are parsed as valid expiry times for session cookies.

Cheers,
Jérémie.
msg233579 - (view) Author: Jérémie Detrey (jdetrey) * Date: 2015-01-07 14:11
Hi again,

Attached is a patch for adding test cases to test_cookiejar.

Cheers,
Jérémie.
msg335081 - (view) Author: Ramy Abdel-Azim (Ramy Abdel-Azim) Date: 2019-02-08 13:30
Hi,

Is there any update on this ticket? I would love to use Requests instead of writing a curl command and running it from the command line out of my script but I need this functionality to pull the cookies.txt file in.

Thanks!
_Ramy
msg335095 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2019-02-08 16:39
Hi Ramy, thanks for bumping the issue.

The solution suggested by Piotr Dobrogost is backward compatible and I think it's the right thing to do.

I opened a new PR thanks to the patch of Jérémie Detrey.
History
Date User Action Args
2022-04-11 14:57:41adminsetgithub: 61366
2019-02-08 16:39:40remi.lapeyresetmessages: + msg335095
versions: + Python 3.7, Python 3.8, - Python 3.4, Python 3.5
2019-02-08 16:37:13remi.lapeyresetstage: patch review
pull_requests: + pull_request11799
2019-02-08 16:37:05remi.lapeyresetstage: (no value)
pull_requests: + pull_request11798
2019-02-08 16:36:57remi.lapeyresetstage: (no value)
pull_requests: + pull_request11797
2019-02-08 15:40:38remi.lapeyresetnosy: + remi.lapeyre
2019-02-08 13:30:43Ramy Abdel-Azimsetnosy: + Ramy Abdel-Azim
messages: + msg335081
2015-01-07 14:11:05jdetreysetfiles: + session-cookies-test.patch

messages: + msg233579
2015-01-07 10:33:05jdetreysetfiles: + session-cookies.patch
versions: + Python 3.6
nosy: + jdetrey

messages: + msg233574

keywords: + patch
2013-02-20 13:05:05piotr.dobrogostsetmessages: + msg182501
2013-02-10 19:26:35orsenthilsetnosy: + orsenthil
2013-02-08 21:23:23piotr.dobrogostcreate