Skip to content
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

[instagram] An unexpected error occurred: KeyError - "name='csrftoken', domain=None, path=None" #1631

Closed
renamed1337 opened this issue Jun 16, 2021 · 11 comments

Comments

@renamed1337
Copy link

I changed my notebook and after installing python3 and the pip version of gallery-dl, i cant download any more. I pretty sure the error lays on my side, but i cant solve this alone.

The user and password are correct.

PS C:\Temp> gallery-dl -u *** -p *** https://www.instagram.com/euro2020/ --sleep 15 --verbose
[gallery-dl][debug] Version 1.17.5
[gallery-dl][debug] Python 3.9.5 - Windows-10-10.0.19043-SP0
[gallery-dl][debug] requests 2.22.0 - urllib3 1.25.8
[gallery-dl][debug] Starting DownloadJob for 'https://www.instagram.com/euro2020/'
[instagram][debug] Using InstagramUserExtractor for 'https://www.instagram.com/euro2020/'
[instagram][debug] Using InstagramPostsExtractor for 'https://www.instagram.com/euro2020/posts/'
[instagram][info] Logging in as ***
[urllib3.connectionpool][debug] Starting new HTTPS connection (1): www.instagram.com:443
[urllib3.connectionpool][debug] https://www.instagram.com:443 "GET /accounts/login/ HTTP/1.1" 200 20173
[instagram][debug] Sleeping for 4.999 seconds
[urllib3.connectionpool][debug] https://www.instagram.com:443 "GET /web/__mid/ HTTP/1.1" 200 28
[instagram][error] An unexpected error occurred: KeyError - "name='csrftoken', domain=None, path=None". Please run gallery-dl again with the --verbose flag, copy its output and report this issue on https://github.com/mikf/gallery-dl/issues .
[instagram][debug]
Traceback (most recent call last):
File "c:\users\xyz\appdata\local\programs\python\python39\lib\site-packages\gallery_dl\job.py", line 74, in run
for msg in self.extractor:
File "c:\users\xyz\appdata\local\programs\python\python39\lib\site-packages\gallery_dl\extractor\instagram.py", line 43, in items
self.login()
File "c:\users\xyz\appdata\local\programs\python\python39\lib\site-packages\gallery_dl\extractor\instagram.py", line 125, in login
self._update_cookies(self._login_impl(username, password))
File "c:\users\xyz\appdata\local\programs\python\python39\lib\site-packages\gallery_dl\cache.py", line 115, in call
value = self.func(*args, **kwargs)
File "c:\users\xyz\appdata\local\programs\python\python39\lib\site-packages\gallery_dl\extractor\instagram.py", line 142, in _login_impl
headers["X-CSRFToken"] = response.cookies["csrftoken"]
File "C:\Users\xyz\AppData\Roaming\Python\Python39\site-packages\requests\cookies.py", line 328, in getitem
return self._find_no_duplicates(name)
File "C:\Users\xyz\AppData\Roaming\Python\Python39\site-packages\requests\cookies.py", line 399, in _find_no_duplicates
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='csrftoken', domain=None, path=None"

Can somebody help me out?

@rod-giovany
Copy link

try to use double-quotes, example: -u "user901" -p "cont4325"
try to update requests, with:

pip install --upgrade requests

or try to use cookies as in: https://github.com/mikf/gallery-dl#cookies, https://github.com/mikf/gallery-dl/blob/master/docs/configuration.rst#extractorcookies
Get cookies.txt
note: you must login first to have the correct "login" cookies

@renamed1337
Copy link
Author

renamed1337 commented Jun 16, 2021

Thank you for your fast answer:

try to use double-quotes, example: -u "user901" -p "cont4325"
I tried it, doesn't change the output.
try to update requests, with:
Done, didn't help.
or try to use cookies as in: https://github.com/mikf/gallery-dl#cookies, https://github.com/mikf/gallery-dl/blob/master/docs/configuration.rst#extractorcookies
Get cookies.txt
note: you must login first to have the correct "login" cookies
I installed the addon and creates a cookie.txt file, but loading it into the program fails?
PS C:\ABC\GD> gallery-dl --cookies "C:\ABC\cookies.txt" instagram
[gallery-dl][error] No suitable extractor found for 'instagram'

Same for instagram.com

@rod-giovany
Copy link

rod-giovany commented Jun 16, 2021

I installed the addon and creates a cookie.txt file, but loading it into the program fails?
PS C:\ABC\GD> gallery-dl --cookies "C:\ABC\cookies.txt" instagram
[gallery-dl][error] No suitable extractor found for 'instagram'

No no no.
using Get cookies.txt, in instagram extract cookies like this:
image
or
image

the file is downloaded as: instagram.com_cookies.txt, and you will use it like this, specifying the path of the downloaded file or its location.
example:

C:\Users\Jonathan>gallery-dl --cookies "C:\Users\Jonathan\Documents\gall\instagram.com_cookies.txt" "https://www.instagram.com/euro2020/"

or in the configuration file (gallery-dl.conf):
image

@rod-giovany
Copy link

still try clearing the cache.

gallery-dl --clear-cache "instagram"

and do the following to see if it gave the same result:

C:\Users\Jonathan>gallery-dl --ignore-config  https://www.instagram.com/euro2020/ --verbose -u "/*secret*/" -p "/*secret*/" --no-download --sleep "15"
[gallery-dl][debug] Version 1.17.5
[gallery-dl][debug] Python 3.9.5 - Windows-10-10.0.19043-SP0
[gallery-dl][debug] requests 2.25.1 - urllib3 1.26.4
[gallery-dl][debug] Starting DownloadJob for 'https://www.instagram.com/euro2020/'
[instagram][debug] Using InstagramUserExtractor for 'https://www.instagram.com/euro2020/'
[instagram][debug] Using InstagramPostsExtractor for 'https://www.instagram.com/euro2020/posts/'
[instagram][info] Logging in as /*secret*/
[urllib3.connectionpool][debug] Starting new HTTPS connection (1): www.instagram.com:443
[urllib3.connectionpool][debug] https://www.instagram.com:443 "GET /accounts/login/ HTTP/1.1" 200 20152
[instagram][debug] Sleeping for 5.0 seconds
[urllib3.connectionpool][debug] https://www.instagram.com:443 "GET /web/__mid/ HTTP/1.1" 200 28
[instagram][debug] Sleeping for 5.0 seconds
[urllib3.connectionpool][debug] https://www.instagram.com:443 "POST /accounts/login/ajax/ HTTP/1.1" 200 109
[instagram][debug] Sleeping for 4.856 seconds
[urllib3.connectionpool][debug] https://www.instagram.com:443 "GET /euro2020/ HTTP/1.1" 200 77343
# .\gallery-dl\instagram\euro2020\2597522892941305610.jpg
# .\gallery-dl\instagram\euro2020\2597515052990197579.jpg
................

The only thing I can think of is that the cache.sqlite3 file is corrupted or does not exist directly, which is rare since it is created and modified automatically.
I don't know what to do in that case.
try uninstalling and reinstalling gallery-dl:

pip uninstall gallery-dl
-------------
pip install gallery-dl

or try clearing the cache specifying to instagram, like my example.

@mikf
Copy link
Owner

mikf commented Jun 16, 2021

Instagram has changed its login procedure, it seems. Any new login ([instagram][info] Logging in as ***) now fails with the error reported above, or at least this also happens for me.
Using cookies directly, as rod-giovany already pointed out, should still work.

@mikf mikf changed the title An unexpected error occurred: KeyError - "name='csrftoken', domain=None, path=None" [instagram] An unexpected error occurred: KeyError - "name='csrftoken', domain=None, path=None" Jun 16, 2021
@renamed1337
Copy link
Author

Okay, the cookies method works :)

Another noob question, is the gallery-dl.conf created while installing gallery-dl or do i need to create and fill it out myself?

@rod-giovany
Copy link

Okay, the cookies method works :)

nice

is the gallery-dl.conf created while installing gallery-dl or do i need to create and fill it out myself?

not.
The gallery-dl.conf file is created and configured manually, but I recommend that you see other issues where I think that several have already had doubts about the same problem, or open a new issue asking.


I recommend you close this one and start a new one about your doubts.
name example:
[Q] "gallery-dl" configuration file format

@mikf mikf closed this as completed in 23018a4 Jun 18, 2021
@mikf
Copy link
Owner

mikf commented Jun 18, 2021

is the gallery-dl.conf created while installing gallery-dl or do i need to create and fill it out myself?

You have to create it yourself. You can use this as a template, though.

@policebro69

This comment was marked as off-topic.

@Folgore5

This comment was marked as off-topic.

@HIMMATGAMER

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants