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

Youtube.com + cookies: 'unicode' object has no attribute 'items' #28640

Closed
6 tasks done
Suika opened this issue Apr 2, 2021 · 13 comments
Closed
6 tasks done

Youtube.com + cookies: 'unicode' object has no attribute 'items' #28640

Suika opened this issue Apr 2, 2021 · 13 comments

Comments

@Suika
Copy link

Suika commented Apr 2, 2021

Checklist

  • I'm reporting a broken site support issue
  • I've verified that I'm running youtube-dl version 2021.04.01
  • 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 bug reports including closed ones
  • I've read bugs section in FAQ

Verbose log

$ youtube-dl -v --cookies=/tmp/ytdljar.txt https://www.youtube.com/watch\?v\=vP3rYUNmrgU
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'-v', u'--cookies=/tmp/ytdljar.txt', u'https://www.youtube.com/watch?v=vP3rYUNmrgU']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2021.04.01
[debug] Python version 2.7.13 (CPython) - Linux-4.15.18-10-pve-x86_64-with-debian-9.13
[debug] exe versions: ffmpeg 3.3.9, ffprobe 3.3.9
[debug] Proxy map: {}
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/bin/youtube-dl/__main__.py", line 19, in <module>
  File "/usr/local/bin/youtube-dl/youtube_dl/__init__.py", line 475, in main
  File "/usr/local/bin/youtube-dl/youtube_dl/__init__.py", line 465, in _real_main
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 2060, in download
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 799, in extract_info
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 806, in wrapper
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 827, in __extract_info
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 533, in extract
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 437, in initialize
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/youtube.py", line 268, in _real_initialize
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/youtube.py", line 253, in _initialize_consent
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 2902, in _get_cookies
  File "/usr/lib/python2.7/Cookie.py", line 583, in __init__
    if input: self.load(input)
  File "/usr/lib/python2.7/Cookie.py", line 643, in load
    for k, v in rawdata.items():
AttributeError: 'unicode' object has no attribute 'items'


Description

Since as of two days ago, 31 March 2021, youtube.com stopped working when using cookies and youtube-dl version 2021.04.01
I tested the --username/--password parameters and indeed I can login and download videos.

So, I pulled the youtube-dl version 2021.03.31 and it was able to download videos using cookies. So something between 8f493de and ca304be messed up the way cookies are being processed.

@Suika
Copy link
Author

Suika commented Apr 2, 2021

For context on cookies I have:

  1. Login into google and youtube
  2. Get something like https://github.com/lennonhill/cookies-txt and export all cookies
  3. Strip #HttpOnly_ from the cookies.
  4. Use the cookies with youtube-dl

@KerfuffleV2
Copy link

@Suika It doesn't seem to work with python2 anymore. Manually running python3 on it (even though it's compressed) does work though. On Unix at least, it has #!env python so if your default python is python2, it will now fail.

@rautamiekka
Copy link
Contributor

I can't speak for non-Debian-type Linux distros, but there you can install the python-is-python3 package.

^ However, the problem's that if anything uses Python 2-exclusive scripts, they'll break. I know Ubuntu's latest versions are using Python 3-exclusive scripts and Python 2 was relocated to multiverse repo (which is disabled by default IIRC), so Ubuntu is safe.

Alternatively you can make a shell alias like so:

##If in ${PATH}:
alias youtube-dl='python3 youtube-dl '

##If not in ${PATH}:
alias youtube-dl='python3 /path/to/youtube-dl '

Notice the trailing space !

@Suika
Copy link
Author

Suika commented Apr 3, 2021

Nice knowing all that, but the docs list support for python 2.6/2.7. Sadly it is still a bug that needs fixing, as it breaks that version "support".
But at least I know that it works with py3.

@rautamiekka
Copy link
Contributor

I'm sure they'll soon figure out the cause.

On a passing note, you should always quote Internet addresses instead of trying to work around the shell processing like you did with the question mark and equal sign: since you're on Linux (or if you were using Micro$oft PowerShell), just single-quote (double-quoting should work for every other shell, including Command Prompt on Window$) the whole address to save yourself massive amounts of headache.

@hedii
Copy link
Contributor

hedii commented Apr 3, 2021

@remitamine can you please make a new release with the fix you've just commited?

github-actions bot added a commit to hellopony/youtube-dl that referenced this issue Apr 3, 2021
* https://github.com/ytdl-org/youtube-dl:
  [youtube] prioritize information from YoutubeIE for playlist entries(closes ytdl-org#28619, closes ytdl-org#28636)
  [extractor/common] fix _get_cookies method for python 2(ytdl-org#20673, ytdl-org#23256, ytdl-org#20326, closes ytdl-org#28640)
@jomyer
Copy link

jomyer commented Apr 4, 2021

Your fix worked beautifully:

alias youtube-dl='python3 /path/to/youtube-dl '

Thank you so much.

@the-saddest-clown
Copy link

I can't speak for non-Debian-type Linux distros, but there you can install the python-is-python3 package.

^ However, the problem's that if anything uses Python 2-exclusive scripts, they'll break. I know Ubuntu's latest versions are using Python 3-exclusive scripts and Python 2 was relocated to multiverse repo (which is disabled by default IIRC), so Ubuntu is safe.

Alternatively you can make a shell alias like so:

##If in ${PATH}:
alias youtube-dl='python3 youtube-dl '

##If not in ${PATH}:
alias youtube-dl='python3 /path/to/youtube-dl '

Notice the trailing space !

Using this fix do work for downloading video but I just try to run the command sudo youtube-dl -U and it gives the error /usr/bin/env: «python»: No such file or directory.
Any hint?

@rautamiekka
Copy link
Contributor

That's exactly your problem: python binary doesn't exist while python3 does, so you need to install the python-is-python3 package. Since your system doesn't come with Python 2 pre-installed, the package is safe to install.

@the-saddest-clown
Copy link

There isn't a workaround for this issue like a shell alias? I prefer not installing this package for now if I had to use a program relying on python2. I can wait for a further version of youtube-dl which implement the fix though.

@hedii
Copy link
Contributor

hedii commented Apr 26, 2021

@the-saddest-clown the fix for this issue has been released 20 days ago. Just update your version of youtube-dl

@the-saddest-clown
Copy link

OK deleted the old /usr/local/bin/youtube-dl and reinstalled the last version 2021.04.26. It works. As long as youtube-dl -U was broken I was not able to upgrade using the command line. Still needs to use the Python alias trick though. Thanks all.

@rautamiekka
Copy link
Contributor

I already told you the shell alias approach, too.

I created+tested a Bash script which "modifies" ytdl to use Python 3 when executed. It's a quick hack, it doesn't actually modify anything, it simply creates a shell script which uses the same shebang ytdl currently does, then appends the latest actual ytdl binary into the file, the same way as ytdl's executable binary's created.

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

No branches or pull requests

6 participants