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

Twitch: login failure due to missing twitchguard code #23337

Open
david-wm-sanders opened this issue Dec 6, 2019 · 8 comments
Open

Twitch: login failure due to missing twitchguard code #23337

david-wm-sanders opened this issue Dec 6, 2019 · 8 comments

Comments

@david-wm-sanders
Copy link

@david-wm-sanders david-wm-sanders commented Dec 6, 2019

Checklist

  • I'm reporting a broken site support
  • I've verified that I'm running youtube-dl version 2019.11.28
  • I've checked that all provided URLs are alive and playable in a browser
  • I've checked that all URLs and arguments with special characters are properly quoted or escaped
  • I've searched the bugtracker for similar issues including closed ones

Verbose log

[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['https://www.twitch.tv/videos/<redacted>', '-u', 'PRIVATE', '-v']
Type account password and press [Return]:
[debug] Encodings: locale cp1252, fs mbcs, out cp850, pref cp1252
[debug] youtube-dl version 2019.11.28
[debug] Python version 3.4.4 (CPython) - Windows-10-10.0.18362
[debug] exe versions: ffmpeg N-92498-g77bf85515e, ffprobe N-92498-g77bf85515e
[debug] Proxy map: {}
[twitch:vod] Downloading login page
[twitch:vod] Logging in
ERROR: Unable to login. Twitch said: missing twitchguard code
Traceback (most recent call last):
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\ytdl-org\tmpwy0zjfmc\build\youtube_dl\YoutubeDL.py", line 796, in extract_info
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\ytdl-org\tmpwy0zjfmc\build\youtube_dl\extractor\common.py", line 529, in extract
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\ytdl-org\tmpwy0zjfmc\build\youtube_dl\extractor\common.py", line 433, in initialize
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\ytdl-org\tmpwy0zjfmc\build\youtube_dl\extractor\twitch.py", line 64, in _real_initialize
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\ytdl-org\tmpwy0zjfmc\build\youtube_dl\extractor\twitch.py", line 119, in _login
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\ytdl-org\tmpwy0zjfmc\build\youtube_dl\extractor\twitch.py", line 96, in login_step
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\ytdl-org\tmpwy0zjfmc\build\youtube_dl\extractor\twitch.py", line 73, in fail
youtube_dl.utils.ExtractorError: Unable to login. Twitch said: missing twitchguard code

Description

On trying to download a video from Twitch, I received the error as shown above. The video is open to subscribers only at the moment, hence the need to provide a username (with -u) and provide the account password at the prompt. On providing the password, login fails with a "missing twitchguard code" error message.

I ran youtube-dl again with --dump-pages and it shows:

[debug] Proxy map: {}
[twitch:vod] Downloading login page
[twitch:vod] Dumping request to https://www.twitch.tv/login
<large base64 encoded dump>
[twitch:vod] Logging in
[twitch:vod] Dumping request to https://passport.twitch.tv/login
<smaller base64 encoded dump>
ERROR: Unable to login. Twitch said: missing twitchguard code

The smaller base64 encoded dump, decoded with base64.b64decode(dump), shows:

b'{"captcha_proof":"<redacted>","error":"Please enter a Login Verification Code.","error_code":3022,"error_description":"missing twitchguard code"}'

It seems like Twitch have introduced a form of login verification - I received an email from Twitch with the subject "Your Twitch Login Verification Code" shortly after running youtube-dl, however there is no prompt by youtube-dl to provide this code in order to continue logging in.

As a note, if I enter an invalid password for the account, I still get youtube_dl.utils.ExtractorError: Unable to login. Twitch said: invalid password so I am sure that the above error occurs after the password has been validated as correct by Twitch.

@colakong
Copy link

@colakong colakong commented Dec 16, 2019

This patch worked for me. I didn't see a generic way of passing cli params into InfoExtractor objects on/after creation, so I updated YoutubeDL.extract_info method to check for the new --twitch-guard-code cli param, and set it in the info extractor object if found. The twitch info extractors then include it during auth if it's set.

I applied the patch to a fork of youtube-dl, but I'm not going to PR it because there should be a more generic way of applying cli params to arbitrary IE's.

With the patch, the workflow is:

  1. Issue the youtube-dl command
  2. Login fails, you get an email with twitch guard code
  3. Issue same youtube-dl command, this time with --twitch-guard-code specified for the code in your email

Update: Twitch now returns ERROR: Unable to login. Twitch said: captcha incorrect so the patch isn't a solution anymore. Captcha would need to be determined and included in a "captcha":{"proof":"_stuff here_"} part of the auth payload.

@PolygraphMusic
Copy link

@PolygraphMusic PolygraphMusic commented Dec 18, 2019

@colakong i have the same issue with twitch.
"ERROR: Unable to login. Twitch said: captcha incorrect"
Don't know what to do with this at the moment.
Hope it will be solved.

@david-wm-sanders
Copy link
Author

@david-wm-sanders david-wm-sanders commented Dec 20, 2019

@PolygraphMusic

The only workaround at the moment seems to be to use the --cookies option for youtube-dl as detailed here.

In short:

  1. Extract the cookies for domain .twitch.tv from your browser (see the link above for extensions that do this extraction for you) to cookies.txt
  2. Run youtube-dl.exe --cookies=cookies.txt https://www.twitch.tv/videos/<numeric_id> (do not use the youtube-dl --username or --password options in this case)
@colakong
Copy link

@colakong colakong commented Dec 20, 2019

@Renzlo-D
Copy link

@Renzlo-D Renzlo-D commented Dec 20, 2019

@david-wm-sanders

Now I get this:
ERROR: Failed to download m3u8 information: HTTP Error 403: Forbidden (caused by HTTPError())

@david-wm-sanders
Copy link
Author

@david-wm-sanders david-wm-sanders commented Dec 20, 2019

@CLUexe

Could you provide the full output with youtube-dl's --verbose option?

At a guess though, I'd say either your cookies (in the cookies file) are expired or, perhaps more likely, youtube-dl can't find the cookies file.

For example, I got a HTTP 403 Forbidden error when I didn't pass the path to the cookies file correctly. I think it showed up as HTTP 403 but when I ran with --verbose I could see that other errors, like the invalid argument below, had been suppressed:

OSError: [Errno 22] Invalid argument: "C:\\Users\\david\\projects\\twitchget\\cookies.txt"

@Renzlo-D
Copy link

@Renzlo-D Renzlo-D commented Dec 21, 2019

@david-wm-sanders

You were spot on, it had something to do with the cookies. The cookies from my Chrome browser gave me the errors but I tried using fresh cookies from Firefox and it worked. Honestly this stuff makes no sense to me if chrome can use the older cookies but youtube-dl can't. Anyway, thanks for your help!

edit: Now that I think about it, when I logged in using firefox it did send me a code to my email to verify, so that's probably why the older cookies worked on chrome and not ytdl.

@reallyuniquename
Copy link

@reallyuniquename reallyuniquename commented Jul 14, 2020

If you don't want to bother with cookies.txt file you can just dump complete Cookie header from network tab of your favorite browser and supply it to yt-dl:
youtube-dl --add-header "Cookie: unique_id=123; server_session=abcdef" https://www.twitch.tv/videos/12345678

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

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.