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

Not sure if it's a bug in youtube-dl or cookiejar.py GBK codec can't decode #16131

Closed
HoldOnBro opened this issue Apr 8, 2018 · 3 comments
Closed

Comments

@HoldOnBro
Copy link

@HoldOnBro HoldOnBro commented Apr 8, 2018

Please follow the guide below

  • You will be asked some questions and requested to provide some information, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your issue (like this: [x])
  • Use the Preview tab to see what your issue will actually look like

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2018.04.03. 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 2018.04.03

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
  • Checked that provided video/audio/playlist URLs (if any) are alive and playable in a browser

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

C:\Windows\system32>youtube-dl --proxy "socks5://127.0.0.1:1080/" --cookies "D:/lynda download/cookies.txt" -v --all-subs -o "Lynda.com - %(playlist)s/%(chapter_number)s - %(chapter)s/%(playlist_index)s - %(title)s.%(ext)s" "https://www.lynda.com/Photography-tutorials/Advanced-Photography-Medium-Format-Digital-Cameras/647680-2.html"
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['--proxy', 'socks5://127.0.0.1:1080/', '--cookies', 'D:/lynda download/cookies.txt', '-v', '--all-subs', '-o', 'Lynda.com - %(playlist)s/%(chapter_number)s - %(chapter)s/%(playlist_index)s - %(title)s.%(ext)s', 'https://www.lynda.com/Photography-tutorials/Advanced-Photography-Medium-Format-Digital-Cameras/647680-2.html']
c:\users\张心阳\appdata\local\programs\python\python36\lib\http\cookiejar.py:2061: UserWarning: http.cookiejar bug!
Traceback (most recent call last):
  File "c:\users\张心阳\appdata\local\programs\python\python36\lib\http\cookiejar.py", line 2011, in _really_load
    line = f.readline()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x82 in position 663: illegal multibyte sequence

  _warn_unhandled_exception()
Traceback (most recent call last):
  File "c:\users\张心阳\appdata\local\programs\python\python36\lib\http\cookiejar.py", line 2011, in _really_load
    line = f.readline()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x82 in position 663: illegal multibyte sequence

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\张心阳\appdata\local\programs\python\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\张心阳\appdata\local\programs\python\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\张心阳\AppData\Local\Programs\Python\Python36\Scripts\youtube-dl.exe\__main__.py", line 9, in <module>
  File "c:\users\张心阳\appdata\local\programs\python\python36\lib\site-packages\youtube_dl\__init__.py", line 471, in main
    _real_main(argv)
  File "c:\users\张心阳\appdata\local\programs\python\python36\lib\site-packages\youtube_dl\__init__.py", line 438, in _real_main
    with YoutubeDL(ydl_opts) as ydl:
  File "c:\users\张心阳\appdata\local\programs\python\python36\lib\site-packages\youtube_dl\YoutubeDL.py", line 411, in __init__
    self._setup_opener()
  File "c:\users\张心阳\appdata\local\programs\python\python36\lib\site-packages\youtube_dl\YoutubeDL.py", line 2291, in _setup_opener
    self.cookiejar.load()
  File "c:\users\张心阳\appdata\local\programs\python\python36\lib\http\cookiejar.py", line 1784, in load
    self._really_load(f, filename, ignore_discard, ignore_expires)
  File "c:\users\张心阳\appdata\local\programs\python\python36\lib\http\cookiejar.py", line 2063, in _really_load
    (filename, line))
http.cookiejar.LoadError: invalid Netscape format cookies file 'D:/lynda download/cookies.txt': 'www.telerik.com\tFALSE\t/\tFALSE\t1679055717\tki_t\t1521288091697%3B1521288091697%3B1521289317673%3B1%3B8'

this problem only occurs when Im using youtube-dl under python3
Under python2, I can download the full course perfectly
while I use

D:\>python3
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys; print(sys.getdefaultencoding())
utf-8
>>>

as above, python3 gives me a default encoding as UTF8

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Apr 8, 2018

Cookie file must be in locale.getpreferredencoding(False) encoding.

@HoldOnBro
Copy link
Author

@HoldOnBro HoldOnBro commented Apr 9, 2018

@dstftw Sorry to bother, but how can I change the locale.getpreferredencoding() into False or utf8 in windows?
And after I type the locale.getpreferredencoding(False) in CMD,it still return a cp936 which means GBK as well

@keenlovelife
Copy link

@keenlovelife keenlovelife commented Jan 13, 2020

目前我也遇到了这个问题,gbk编码出错。现在我已经解决了。

(抱歉,刚才注意到您的版本是2018的,目前的版本是2020.01.01,但是刚才我查看了您的错误信息,并且查看了 cookiejar.py的源码,发现似乎都是同样的问题,可以使用同样的解决方法来解决,后面我写下了您的问题的解决办法,但是是我推测的,并不保证一定有效。)

我自己遇到的问题的解决办法如下:

  1. 你需要通过使用 youtube-dl 的源码来运行您的下载任务(下载视频),如果是 youtube-dl.exe 将无法修改。
  2. 在源码文件找到 youtube_dl/options.py
  3. 在 options.py 中找到 第44行,你可以看到这行代码: optionf = open(filename_bytes)
  4. 将其修改为:optionf = open(filename_bytes, 'r', encoding='UTF-8')
  5. 保存
  6. 关闭命令行
  7. 重开打开命令行,并运行 youtube-dl [URL] 命令

经过上面的修改,您的程序应该能够正常运行了,因为我目前就是这样解决的。

而您的错误信息中指向了 cookiejar.py 这个文件,并且 提到 self._really_load
这个出错的位置。因此您需要:

  1. 请在"c:\users\张心阳\appdata\local\programs\python\python36\lib\http\cookiejar.py" 路径中找到这个文件: cookiejar.py , 我估计您应该在那个路径下找不到,因此,你仍然需要使用 youtube-dl 源码 来运行程序。
  2. 找到 1798行或者1784行(很可能不是这行,因为我的是2020.01.01版本,不过可以使用在文件中全局搜索 _really_load 来快速找到它,您的错误信息中指示它位于1784行),其中您会看到如下的代码:
        with open(filename) as f:
            self._really_load(f, filename, ignore_discard, ignore_expires)

该处代码是读取文件的初始位置,需要在这里进行修改,使之能够正常读取gbk编码的文件即可。

  1. 将之修改为如下:
        with open(filename, 'r', encoding='UTF-8') as f:
            self._really_load(f, filename, ignore_discard, ignore_expires)
  1. 保存文件
  2. 关闭之前的命令行
  3. 重新开启命令行,执行 youtube-dl [URL] 进行尝试

如此应该就能解决您的问题


machine translation

At present I also encountered this problem, gbk encoding error. Now I have solved it.

(Sorry, just noticed that your version is 2018, and the current version is 2020.01.01, but just now I checked your error message and checked the source code of cookiejar.py. I found that it seems to be the same problem. You can use the same solution to solve it. I wrote the solution to your problem later, but it is my guess and it is not guaranteed to be effective.)

The solution to my own problem is as follows:

  1. You need to run your download task (download video) by using the source code of youtube-dl. If it is youtube-dl.exe, it cannot be modified.
  2. Find youtube_dl / options.py in the source file
  3. Locate line 44 in options.py, you can see this line of code: optionf = open (filename_bytes)
  4. Modify it to: optionf = open (filename_bytes, 'r', encoding = 'UTF-8')
  5. Save
  6. Close the command line
  7. Reopen to open the command line and run the youtube-dl [URL] command

After the above modification, your program should be able to run normally, because this is how I solve it now.

And your error message points to cookiejar.py and mentions self._really_load
 Where this went wrong. So you need to:

  1. Please find this file in " c: \ users \ 张心阳 \ appdata \ local \ programs \ python \ python36 \ lib \ http \ cookiejar.py " path: cookiejar.py, I guess you should be there The path cannot be found, so you still need to use youtube-dl source code to run the program.
  2. Find line 1798 or line 1784 (probably not this line, because my version is 2020.01.01, but you can use global search in the file _really_load to quickly find it, as indicated in your error It's on line 1784), where you will see the following code:
        with open (filename) as f:
            self._really_load (f, filename, ignore_discard, ignore_expires)

The code here is the initial position for reading the file. It needs to be modified here so that it can read the gbk encoded file normally.

  1. Amend it as follows:
        with open (filename, 'r', encoding = 'UTF-8') as f:
            self._really_load (f, filename, ignore_discard, ignore_expires)
  1. Save the file
  2. Close the previous command line
  3. Restart the command line and execute youtube-dl [URL] to try

This should solve your problem

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
3 participants
You can’t perform that action at this time.