hydrus icon indicating copy to clipboard operation
hydrus copied to clipboard

Cookie Import Error AddCookieToSessionActualCookie() missing 1 required positional argument: 'cookie'

Open TacoMagick opened this issue 7 months ago • 6 comments

Hydrus version

v670

Qt major version

Qt 6

Operating system

Windows 11

Install method

Extract

Install and OS comments

Updating from v668 to v670 deleted the "lib" folder and extracted the zip contents, overwrote the executables.

Bug description and reproduction

1. network > data > review session cookies
2. Export Firefox cookies for site using [cookies.txt](https://addons.mozilla.org/en-US/firefox/addon/cookies-txt/) in Netscape format (this is probably not an extension issue because it works with other tools such as yt-dlp)
3. click "import cookies.txt (drag and drop also works!"
4. select cookies.txt location
5. Type Error
1. network > data > review session cookies
2. Copy Firefox cookies using [cookies.txt](https://addons.mozilla.org/en-US/firefox/addon/cookies-txt/)
3. click "import from clipboard"
4. "Did not understand what was in the clipboard Extra data: line 1 column 2 (char 1)"
1. network > data > review session cookies
2. Export ALL Firefox cookies using [cookies.txt](https://addons.mozilla.org/en-US/firefox/addon/cookies-txt/) in Netscape format (this is probably not an extension issue because it works with other tools such as yt-dlp)
3. click "import cookies.txt (drag and drop also works!"
4. select cookies.txt location
5. "It looks like that cookies.txt failed to load. Unfortunately, not all formats are supported" LoadError invalid netscape format cookies file 

Log output

v670, win32, frozen
TypeError
AddCookieToSessionActualCookie() missing 1 required positional argument: 'cookie'
================ Exception ================
TypeError: AddCookieToSessionActualCookie() missing 1 required positional argument: 'cookie'
================ Traceback ================
Traceback (most recent call last):
  File "hydrus\client\gui\widgets\ClientGUICommon.py", line 357, in EventButton
  File "hydrus\client\gui\networking\ClientGUINetwork.py", line 1606, in _ImportCookiesTXT
  File "hydrus\client\gui\networking\ClientGUINetwork.py", line 1636, in _ImportCookiesTXTPaths
TypeError: AddCookieToSessionActualCookie() missing 1 required positional argument: 'cookie'
================== Stack ==================
  File "hydrus_client.pyw", line 11, in <module>
  File "hydrus\hydrus_client_boot.py", line 272, in boot
  File "hydrus\client\ClientController.py", line 1971, in Run
  File "qtpy\QtWidgets.py", line 165, in <lambda>
  File "qtpy\_utils.py", line 53, in possibly_static_exec
  File "hydrus\client\ClientData.py", line 30, in CatchExceptionClient
  File "hydrus\client\ClientThreading.py", line 365, in SetExceptionTuple
  File "hydrus\core\HydrusData.py", line 328, in ConvertExceptionTupleToNiceTrace
=================== End ===================


Error 2:

v670, win32, frozen
LoadError
invalid Netscape format cookies file '[PATH]\\cookies.txt': '[WEBSITE]\tFALSE\t/\tFALSE\t1798314891\tbp_ut_session\t%7B-q-pageviews-q-%3A1-c--q-referrer-q-%3A-q-https%3A%2F%2F[WEBSITE]%2Fproduct%2F[PRODUCT]%2Fref%2F448115%2F%3F__cf_chl_tk%3DtLakOgZ0cqIP64IXOMka72i0_dApP1pFuUkg6_5h9X0-1763754882-1.0.1.1-.LICO4knjBxUWsfyTVmYvmId1y0kUAiSDmnVy6Iavbw-q--c--q-landingPage-q-%3A-q-https%3A%2F%2F[WEBSITE]%2Fproduct%2F[PRODUCT]%2Fref%2F448115%2F-q--c--q-started-q-%3A1763754891475%7D'
================ Exception ================
LoadError: invalid Netscape format cookies file '[PATH]\\cookies.txt': '[WEBSITE]\tFALSE\t/\tFALSE\t1798314891\tbp_ut_session\t%7B-q-pageviews-q-%3A1-c--q-referrer-q-%3A-q-https%3A%2F%2F[WEBSITE]%2Fproduct%2F[PRODUCT]%2Fref%2F448115%2F%3F__cf_chl_tk%3DtLakOgZ0cqIP64IXOMka72i0_dApP1pFuUkg6_5h9X0-1763754882-1.0.1.1-.LICO4knjBxUWsfyTVmYvmId1y0kUAiSDmnVy6Iavbw-q--c--q-landingPage-q-%3A-q-https%3A%2F%2F[WEBSITE]%2Fproduct%2F[PRODUCT]%2Fref%2F448115%2F-q--c--q-started-q-%3A1763754891475%7D'
================ Traceback ================
Traceback (most recent call last):
  File "http\cookiejar.py", line 2021, in _really_load
UnicodeDecodeError: 'cp932' codec can't decode byte 0x85 in position 5233: illegal multibyte sequence

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "hydrus\client\gui\networking\ClientGUINetwork.py", line 1621, in _ImportCookiesTXTPaths
  File "http\cookiejar.py", line 1802, in load
  File "http\cookiejar.py", line 2079, in _really_load
http.cookiejar.LoadError: invalid Netscape format cookies file '[PATH]\\cookies.txt': '[WEBSITE]\tFALSE\t/\tFALSE\t1798314891\tbp_ut_session\t%7B-q-pageviews-q-%3A1-c--q-referrer-q-%3A-q-https%3A%2F%2F[WEBSITE]%2Fproduct%2F[PRODUCT]%2Fref%2F448115%2F%3F__cf_chl_tk%3DtLakOgZ0cqIP64IXOMka72i0_dApP1pFuUkg6_5h9X0-1763754882-1.0.1.1-.LICO4knjBxUWsfyTVmYvmId1y0kUAiSDmnVy6Iavbw-q--c--q-landingPage-q-%3A-q-https%3A%2F%2F[WEBSITE]%2Fproduct%2F[PRODUCT]%2Fref%2F448115%2F-q--c--q-started-q-%3A1763754891475%7D'
================== Stack ==================
  File "hydrus_client.pyw", line 11, in <module>
  File "hydrus\hydrus_client_boot.py", line 272, in boot
  File "hydrus\client\ClientController.py", line 1971, in Run
  File "qtpy\QtWidgets.py", line 165, in <lambda>
  File "qtpy\_utils.py", line 53, in possibly_static_exec
  File "hydrus\client\gui\widgets\ClientGUICommon.py", line 357, in EventButton
  File "hydrus\client\gui\networking\ClientGUINetwork.py", line 1606, in _ImportCookiesTXT
  File "hydrus\client\gui\networking\ClientGUINetwork.py", line 1625, in _ImportCookiesTXTPaths
  File "hydrus\client\ClientData.py", line 129, in ShowExceptionClient
  File "hydrus\client\ClientData.py", line 143, in ShowExceptionTupleClient
  File "hydrus\client\ClientThreading.py", line 365, in SetExceptionTuple
  File "hydrus\core\HydrusData.py", line 328, in ConvertExceptionTupleToNiceTrace
=================== End ===================

TacoMagick avatar May 05 '26 07:05 TacoMagick

Thank you for this report! This is a foolish typo by me that slipped by my testing. Sorry for the trouble!

I have just committed a fix to the master branch, and it will be available in the built release v671.

There is some is bad timing as I am in the midst of a larger rewrite right now and will not be doing a release tomorrow as normal. v671 will be out the 13th May. Please bear with me until then.

You actually have two errors here--one that is my fault, and another that suggests your cookies.txt is a little weird and cannot be parsed. Have you tried this before? If so, did the same sort of cookies.txt work ok? Or do you, say, get this error sometimes and some of the cookies import ok anyway?

hydrusnetwork avatar May 05 '26 20:05 hydrusnetwork

The cookies.txt file I use has the following header if it is of any help,

# Netscape HTTP Cookie File
# https://curl.haxx.se/rfc/cookie_spec.html
# This is a generated file! Do not edit.

I tried to use the same cookies.txt in Hydrus v649 and it once again failed. This is strange because I don't really remember it doing this before but also since this specific Hydrus is very old it could be I'm misremembering and my browser has collected some more cookies during that time. The cookie formats of the websites that are returning errors seem pretty normal except the use of underscores in their names such as this specific one:

v649, win32, frozen
LoadError
invalid Netscape format cookies file '[PATH]\\cookies.txt': '.[WEBSITE].site\tTRUE\t/\tFALSE\t1795962908\t__ddg1_\tukoCGryv7rcBOBuxPnUo'
================ Exception ================
LoadError: invalid Netscape format cookies file '[PATH]\\cookies.txt': '.[WEBSITE].site\tTRUE\t/\tFALSE\t1795962908\t__ddg1_\tukoCGryv7rcBOBuxPnUo'
================ Traceback ================
Traceback (most recent call last):
  File "http\cookiejar.py", line 2021, in _really_load
UnicodeDecodeError: 'cp932' codec can't decode byte 0x85 in position 2231: illegal multibyte sequence

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "hydrus\client\gui\networking\ClientGUINetwork.py", line 1599, in _ImportCookiesTXTPaths
  File "http\cookiejar.py", line 1802, in load
  File "http\cookiejar.py", line 2079, in _really_load
http.cookiejar.LoadError: invalid Netscape format cookies file '[PATH]\\cookies.txt': '.[WEBSITE].site\tTRUE\t/\tFALSE\t1795962908\t__ddg1_\tukoCGryv7rcBOBuxPnUo'
================== Stack ==================
  File "hydrus_client.pyw", line 11, in <module>
  File "hydrus\hydrus_client_boot.py", line 256, in boot
  File "hydrus\client\ClientController.py", line 1959, in Run
  File "qtpy\QtWidgets.py", line 165, in <lambda>
  File "qtpy\_utils.py", line 53, in possibly_static_exec
  File "hydrus\client\gui\widgets\ClientGUICommon.py", line 357, in EventButton
  File "hydrus\client\gui\networking\ClientGUINetwork.py", line 1584, in _ImportCookiesTXT
  File "hydrus\client\gui\networking\ClientGUINetwork.py", line 1603, in _ImportCookiesTXTPaths
  File "hydrus\client\ClientData.py", line 174, in ShowExceptionClient
  File "hydrus\client\ClientData.py", line 213, in ShowExceptionTupleClient
  File "hydrus\core\HydrusData.py", line 349, in PrintExceptionTuple
=================== End ===================

Is this truly an issue with the cookies.txt format? If so I'll start looking for an alternative plugin for my browser.

TacoMagick avatar May 05 '26 21:05 TacoMagick

I thiiiink the cookies.txt format is ok but there's a weird character in there. That specific error line:

UnicodeDecodeError: 'cp932' codec can't decode byte 0x85 in position 2231: illegal multibyte sequence

Suggests there is something like a kanji character EDIT: cp932 appears to be Shift-JIS, so yeah something unusual and Japanese encoded in your cookie data and the python http library is uncertain how to decode it. Maybe a username or a setting somewhere.

I do not know what the 'correct' encoding for cookies.txt is. It is probably so old a spec that it is undefined. Pretty much everything uses utf-8 nowadays, so maybe the python library is using the wrong encoding, or the cookies.txt extension you are using to create the .txt is using the wrong encoding, or the website is setting a cookie value using the wrong encoding, or I am failing to properly nudge something in the correct direction.

You are correct to redact your cookies.txt before posting anything from it here. Do not post the whole thing. You might like to look through it and see if there are any funky characters, the stuff that ends up in Japanese ASCII art. Let me know if anything particular stands out. I'll have a look on my end and see if I can do a better job of decoding the file before it gets parsed.

Oh, I should add: if you hit up help->about, what is your apparent locale? It could also be the cookie has utf-8 kanji in some standard way but somehow your locale is pointing to Shift-JIS and that's the decoding issue.

hydrusnetwork avatar May 09 '26 20:05 hydrusnetwork

Ok yeah I have done some more research. I think the cookies.txt file is probably utf-8 or some simple ASCII-like, but your system locale is Shift-JIS or similar, and the python http library appears to be deferring to the system locale encoding when trying to load the cookies.txt. I think I can write a hacky patch for this situation.

hydrusnetwork avatar May 09 '26 21:05 hydrusnetwork

My help->about shows locale as English_United States/en_US however I should mention my region is set as Japan, Device setup region is Japan and Language for non-Unicode programs is once again set to Japanese (Japan) I have the Japanese locale and handwriting packs installed. My display language is English (United States)

The cookies.txt opens as utf-8 on notepad and shows fine. No visible kanji characters (Anything Japanese/Chinese)

I currently cannot test changing my system settings to be English (United States) but I can test any patches and newer versions for this issue. Thanks for your investigation on this topic.

TacoMagick avatar May 10 '26 11:05 TacoMagick

Great, that sounds about correct. This cp932 seems to be what python is selecting as your default, so that's some deep interaction between your OS locale and python. I wrote a patch for v671 where if the normal decode fails like with your error here, it'll try and read the file with utf-8 and then write it back to a temp file using your default locale encoding, and pass that translated temp file to the http lib cookie loader for a second attempt. Let me know how it goes!

It seems like the Official Internet Rules for what characters are ok in cookie values are: 'you can pretty much do whatever you want', but then most people just use simple ASCII to be safe, and that means when a site does put in some 'vowel with accent' or whatever that needs a special encoding, a library that normally works with simple encoding can then run into trouble.

Second part is I broke it with a stupid typo! Both should be fixed this Wed. 🤞

hydrusnetwork avatar May 11 '26 20:05 hydrusnetwork