youtube-dl: [YouTube] Unable to authenticate with enabled TFA

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2017.12.31. If it’s not, read this FAQ entry and update. Issues with outdated version will be rejected.

  • I’ve verified and I assure that I’m running youtube-dl 2017.12.31
D:\downloaded_audio
λ youtube-dl --version
2017.12.31

Before submitting an issue make sure you have:

  • At least skimmed through the README, most notably the FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones

What is the purpose of your issue?

  • Bug report (encountered problems with youtube-dl)
  • Site support request (request for adding support for a new site)
  • Feature request (request for a new functionality)
  • Question
  • Other

If the purpose of this issue is a bug report, site support request or you are not completely sure provide the full verbose output as follows:

Add the -v flag to your command line you run youtube-dl with (youtube-dl -v <your command line>), copy the whole output and insert it here. It should look similar to one below (replace it with your log inserted between triple ```):

[debug] System config: []
[debug] User config: ['-x', '--audio-format', 'mp3', '--audio-quality', '0']
[debug] Custom config: []
[debug] Command-line args: ['-n', '-v', 'https://www.youtube.com/watch?v=tM8x5Zhe5O0']
[debug] Encodings: locale cp1251, fs utf-8, out utf-8, pref cp1251
[debug] youtube-dl version 2017.12.31
[debug] Python version 3.6.3 - Windows-10-10.0.16299-SP0
[debug] exe versions: ffmpeg N-88355-g05beee44c6, ffprobe N-88355-g05beee44c6
[debug] Proxy map: {}
[youtube] Downloading login page
[youtube] Looking up account info
[youtube] Logging in
Type 2-step verification code and press [Return]:
[youtube] Submitting TFA code
WARNING: Unable to submit TFA code: HTTP Error 400: Bad Request
WARNING: Unable to extract CheckCookie URL
[youtube] tM8x5Zhe5O0: Downloading webpage
[youtube] tM8x5Zhe5O0: Downloading video info webpage
ERROR: tM8x5Zhe5O0: YouTube said: Please sign in to view this video.
Traceback (most recent call last):
  File "d:\program files\python36-32\lib\site-packages\youtube_dl\YoutubeDL.py", line 784, in extract_info
    ie_result = ie.extract(url)
  File "d:\program files\python36-32\lib\site-packages\youtube_dl\extractor\common.py", line 438, in extract
    ie_result = self._real_extract(url)
  File "d:\program files\python36-32\lib\site-packages\youtube_dl\extractor\youtube.py", line 1609, in _real_extract
    expected=True, video_id=video_id)
youtube_dl.utils.ExtractorError: tM8x5Zhe5O0: YouTube said: Please sign in to view this video.
[debug] System config: []
[debug] User config: ['-x', '--audio-format', 'mp3', '--audio-quality', '0']
[debug] Custom config: []
[debug] Command-line args: ['-u', 'PRIVATE', '-p', 'PRIVATE', '-v', 'https://www.youtube.com/watch?v=tM8x5Zhe5O0']
[debug] Encodings: locale cp1251, fs utf-8, out utf-8, pref cp1251
[debug] youtube-dl version 2017.12.31
[debug] Python version 3.6.3 - Windows-10-10.0.16299-SP0
[debug] exe versions: ffmpeg N-88355-g05beee44c6, ffprobe N-88355-g05beee44c6
[debug] Proxy map: {}
[youtube] Downloading login page
[youtube] Looking up account info
[youtube] Logging in
Type 2-step verification code and press [Return]:
[youtube] Submitting TFA code
WARNING: Unable to submit TFA code: HTTP Error 400: Bad Request
WARNING: Unable to extract CheckCookie URL
[youtube] tM8x5Zhe5O0: Downloading webpage
[youtube] tM8x5Zhe5O0: Downloading video info webpage
ERROR: tM8x5Zhe5O0: YouTube said: Please sign in to view this video.
Traceback (most recent call last):
  File "d:\program files\python36-32\lib\site-packages\youtube_dl\YoutubeDL.py", line 784, in extract_info
    ie_result = ie.extract(url)
  File "d:\program files\python36-32\lib\site-packages\youtube_dl\extractor\common.py", line 438, in extract
    ie_result = self._real_extract(url)
  File "d:\program files\python36-32\lib\site-packages\youtube_dl\extractor\youtube.py", line 1609, in _real_extract
    expected=True, video_id=video_id)
youtube_dl.utils.ExtractorError: tM8x5Zhe5O0: YouTube said: Please sign in to view this video.
[debug] System config: []
[debug] User config: ['-x', '--audio-format', 'mp3', '--audio-quality', '0']
[debug] Custom config: []
[debug] Command-line args: ['-u', 'PRIVATE', '-p', 'PRIVATE', '-2', '123456', '-v', 'https://www.youtube.com/watch?v=tM8x5Zhe5O0']
[debug] Encodings: locale cp1251, fs utf-8, out utf-8, pref cp1251
[debug] youtube-dl version 2017.12.31
[debug] Python version 3.6.3 - Windows-10-10.0.16299-SP0
[debug] exe versions: ffmpeg N-88355-g05beee44c6, ffprobe N-88355-g05beee44c6
[debug] Proxy map: {}
[youtube] Downloading login page
[youtube] Looking up account info
[youtube] Logging in
[youtube] Submitting TFA code
WARNING: Unable to submit TFA code: HTTP Error 400: Bad Request
WARNING: Unable to extract CheckCookie URL
[youtube] tM8x5Zhe5O0: Downloading webpage
[youtube] tM8x5Zhe5O0: Downloading video info webpage
ERROR: tM8x5Zhe5O0: YouTube said: Please sign in to view this video.
Traceback (most recent call last):
  File "d:\program files\python36-32\lib\site-packages\youtube_dl\YoutubeDL.py", line 784, in extract_info
    ie_result = ie.extract(url)
  File "d:\program files\python36-32\lib\site-packages\youtube_dl\extractor\common.py", line 438, in extract
    ie_result = self._real_extract(url)
  File "d:\program files\python36-32\lib\site-packages\youtube_dl\extractor\youtube.py", line 1609, in _real_extract
    expected=True, video_id=video_id)
youtube_dl.utils.ExtractorError: tM8x5Zhe5O0: YouTube said: Please sign in to view this video.

Description of your issue, suggested solution and other information

Unable to authenticate with enabled TFA on account. Returns HTTP Error 400 after typing 2-step verification code. Happens in any way of authentication: .netrc, direct passing login+pass via cmd args, direct passing login+pass+tfacode via cmd args.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 12
  • Comments: 30 (1 by maintainers)

Most upvoted comments

Receiving same error with Python 2.7.x

[debug] System config: []
[debug] User config: [u'-x', u'--audio-format', u'm4a', u'-o', u'~/Desktop/%(playlist_title)s/%(title)s.%(ext)s']
[debug] Custom config: []
[debug] Command-line args: [u'-v', u'-u', u'PRIVATE', u'-p', u'PRIVATE', u'https://www.youtube.com/playlist?list=WL']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2018.06.04
[debug] Python version 2.7.10 (CPython) - Darwin-17.5.0-x86_64-i386-64bit
[debug] exe versions: ffmpeg 3.3.3, ffprobe 3.3.3, phantomjs 2.1.1
[debug] Proxy map: {}
[youtube:watchlater] Downloading login page
[youtube:watchlater] Looking up account info
[youtube:watchlater] Logging in
Type 2-step verification code and press [Return]:
[youtube:watchlater] Submitting TFA code
WARNING: Unable to submit TFA code: HTTP Error 500: Internal Server Error
[youtube:watchlater] WL: Downloading webpage
ERROR: This playlist does not exist.
Traceback (most recent call last):
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 792, in extract_info
    ie_result = ie.extract(url)
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 500, in extract
    ie_result = self._real_extract(url)
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/youtube.py", line 2790, in _real_extract
    _, playlist = self._extract_playlist('WL')
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/youtube.py", line 2305, in _extract_playlist
    raise ExtractorError(message, expected=True)
ExtractorError: This playlist does not exist.

@Vulp35 I’m working on a fix. What 2FA methods (Authenticator code, texted code, prompt in Google/Gmail app) do you have turned on on your Google account? Which one is the default, the one it asks for when you try to log in with a browser (use incognito if you don’t know)?

Found the same issue just now when attempting to grab my Watch Later for a flight.

[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'-v', u'-i', u'-f', u'bestvideo[ext=mp4]+bestaudio[ext=m4a]', u'--restrict-filenames', u'-u', u'PRIVATE', u'-2', u'397635', u'-o', u'/Users/ryan/Downloads/later/%(title)s.%(ext)s', u'https://www.youtube.com/playlist?list=WL']
Type account password and press [Return]: 
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2018.01.07
[debug] Python version 2.7.10 (CPython) - Darwin-17.3.0-x86_64-i386-64bit
[debug] exe versions: ffmpeg 3.3.3-tessus, ffprobe 3.3.3-tessus, phantomjs 2.1.1
[debug] Proxy map: {}
[youtube:watchlater] Downloading login page
[youtube:watchlater] Looking up account info
[youtube:watchlater] Logging in
[youtube:watchlater] Submitting TFA code
WARNING: Unable to submit TFA code: HTTP Error 500: Internal Server Error
WARNING: Unable to extract CheckCookie URL
[youtube:watchlater] WL: Downloading webpage
ERROR: This playlist does not exist.
Traceback (most recent call last):
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 784, in extract_info
    ie_result = ie.extract(url)
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 438, in extract
    ie_result = self._real_extract(url)
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/youtube.py", line 2737, in _real_extract
    _, playlist = self._extract_playlist('WL')
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/youtube.py", line 2259, in _extract_playlist
    raise ExtractorError(message, expected=True)
ExtractorError: This playlist does not exist.

EDIT: updated to current and re-ran

I am having the same difficulty with the version 2018.11.23 and the forked version that was modified by @eduardog3000 . This was difficult to test on Windows without an executable, but I figured it out. In any case, when I temporarily disable 2FA on my account, both the stock and modified versions worked for me. So I am not sure what the fix was supposed to do, but I saw no change in behavior.

[youtube] Downloading login page
[youtube] Looking up account info
[youtube] Logging in
WARNING: Unable to log in: HTTP Error 400: Bad Request

@eduardog3000 oh gotcha! Yup can also confirm it working with prompt enabled as the default but using a code from Authenticator in youtube-dl

@Vulp35 youtube-dl can’t actually use the prompt, it still needs the Google Authenticator code, but I wanted to make sure that someone with the prompt enabled was still able to use the code through youtube-dl. The way the fix works I wasn’t completely sure it would work when Google asks for the prompt by default.

Oh, good, Prompt started working for me (you can see in my image above I got locked out of it), so I could test it myself.

Looks like all is good, I’ll submit the PR.

@Vulp35 I’m working on a fix. What 2FA methods (Authenticator code, texted code, prompt in Google/Gmail app) do you have turned on on your Google account? Which one is the default, the one it asks for when you try to log in with a browser (use incognito if you don’t know)?

screenshot_2018-12-13 2-step verification

I can add prompt as well if that helps you.

Also, can confirm this fix is working with the Authenticator App 😃

C:\youtube-dl\youtube-dl-tfa-fix>python -m youtube_dl --version
2018.12.09

C:\youtube-dl\youtube-dl-tfa-fix>python -m youtube_dl -v --config-location "C:\youtube-dl\login.conf" https://www.youtube.com/watch?v=8mz5sCAvDAY
[debug] System config: []
[debug] User config: []
[debug] Custom config: [u'-u', u'PRIVATE', u'-p', u'PRIVATE']
[debug] Command-line args: [u'-v', u'--config-location', u'C:\\youtube-dl\\login.conf', u'https://www.youtube.com/watch?v=8mz5sCAvDAY']
[debug] Encodings: locale cp1252, fs mbcs, out cp437, pref cp1252
[debug] youtube-dl version 2018.12.09
[debug] Python version 2.7.14 (CPython) - Windows-10-10.0.17134
[debug] exe versions: ffmpeg 3.4.1, ffprobe 3.4.1
[debug] Proxy map: {}
[youtube] Downloading login page
[youtube] Looking up account info
[youtube] Logging in
Type 2-step verification code and press [Return]:
[youtube] Selecting TOTP TFA challenge
[youtube] Submitting TFA code
[youtube] Checking cookie
[youtube] 8mz5sCAvDAY: Downloading webpage
[youtube] 8mz5sCAvDAY: Downloading video info webpage
[debug] Default format spec: bestvideo+bestaudio/best

@sandalle But it’s good to see my code works for you. Just to be sure, this is the very first screen you see after inputting your password in a normal browser?

Correct, that’s what I see after using a browser in Privacy mode.

@sandalle

$ youtube-dl -u sandalle@gmail.com -p -2 https://www.youtube.com/watch?v=UcRZQL-grSs is because you have the syntax wrong, you have to put your 6 digit TOTP code after -2.

But it’s good to see my code works for you. Just to be sure, this is the very first screen you see after inputting your password in a normal browser?

image

Not something like this:

image

If I were you I’d mask your logins.

@eduardog3000

$ youtube-dl --version
2018.12.09
$ youtube-dl -u someemail@email.com -2 https://www.youtube.com/watch?v=UcRZQL-grSs
Type account password and press [Return]:
Usage: youtube-dl [OPTIONS] URL [URL...]

youtube-dl: error: You must provide at least one URL.
Type youtube-dl --help to see a list of all options.
$ youtube-dl -u someemail@email.com -p -2 https://www.youtube.com/watch?v=UcRZQL-grSs
[youtube] Downloading login page
[youtube] Looking up account info
[youtube] Logging in
WARNING: Unable to login: Invalid password
[youtube] UcRZQL-grSs: Downloading webpage
[youtube] UcRZQL-grSs: Downloading video info webpage
^C
ERROR: Interrupted by user

I’m unsure why those aren’t working, but using my ~/.netrc values worked in that I got HTTP Error 500 for 2FA:

$ youtube-dl -n https://www.youtube.com/watch?v=UcRZQL-grSs
[youtube] Downloading login page
[youtube] Looking up account info
[youtube] Logging in
Type 2-step verification code and press [Return]:
[youtube] Submitting TFA code
WARNING: Unable to submit TFA code: HTTP Error 500: Internal Server Error
[youtube] UcRZQL-grSs: Downloading webpage
[youtube] UcRZQL-grSs: Downloading video info webpage
[download] Destination: The Diver's Grave _ Critical Role _ Campaign 2, Episode 44-UcRZQL-grSs.mp4
[download]   0.1% of 920.30MiB at 814.70KiB/s ETA 19:16^C
ERROR: Interrupted by user

I’ve cloned git@github.com:eduardog3000/youtube-dl.git seems to work with 2FA. 😃

$ git checkout -b tfa-fix origin/tfa-fix
Branch 'tfa-fix' set up to track remote branch 'tfa-fix' from 'origin'.
Switched to a new branch 'tfa-fix'
$ python -m youtube_dl --version
2018.12.09
$ python -m youtube_dl -v -n https://www.youtube.com/watch?v=UcRZQL-grSs
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'-v', u'-n', u'https://www.youtube.com/watch?v=UcRZQL-grSs']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2018.12.09
[debug] Git HEAD: 40217df7e
[debug] Python version 2.7.15 (CPython) - Darwin-18.2.0-x86_64-i386-64bit
[debug] exe versions: none
[debug] Proxy map: {}
[youtube] Downloading login page
[youtube] Looking up account info
[youtube] Logging in
Type 2-step verification code and press [Return]:
[youtube] Selecting TOTP TFA challenge
[youtube] Submitting TFA code
[youtube] Checking cookie
[youtube] UcRZQL-grSs: Downloading webpage
[youtube] UcRZQL-grSs: Downloading video info webpage
[debug] Default format spec: best/bestvideo+bestaudio
[debug] Invoking downloader on u'somelongURL'
[download] Resuming download at byte 6225101
[download] Destination: The Diver's Grave _ Critical Role _ Campaign 2, Episode 44-UcRZQL-grSs.mp4
[download]   1.1% of 920.30MiB at 275.75KiB/s ETA 56:21^C
ERROR: Interrupted by user

I also tried downloading a playlist, and the first item worked with 2FA and the second continued to work with the 2FA session. 😃

[youtube] Checking cookie
[youtube] YW01AC2NJAc: Downloading webpage
[youtube] YW01AC2NJAc: Downloading video info webpage
[youtube] YW01AC2NJAc: Marking watched

@sandalle What error do you get when you try to log in with youtube-dl? HTTP Error 500: Internal Server Error or HTTP Error 400: Bad Request.

Then can you download this branch and tell me what happens when you try to log in (use python -m youtube_dl -v <args> to run directly from the code).

@eduardog3000 , for mine, my YouTube 2FA is via Google Authenticator.

Enter a verification code
Get a verification code from the Google Authenticator app
Enter the 6-digit code