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

KeyError on initialising YoutubeDL in python3 #3910

Closed
Dockheas23 opened this issue Oct 9, 2014 · 0 comments
Closed

KeyError on initialising YoutubeDL in python3 #3910

Dockheas23 opened this issue Oct 9, 2014 · 0 comments

Comments

@Dockheas23
Copy link
Contributor

@Dockheas23 Dockheas23 commented Oct 9, 2014

Hello,

When instantiating a YoutubeDL on python3 without having the locale properly set, I get a KeyError, due to params not having restrictfilenames set. I can simulate it by setting LC_ALL to 'ascii'.

ubuntu@localhost:~$ LC_ALL=ascii python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getfilesystemencoding()
'ascii'
>>> from youtube_dl import YoutubeDL
>>> yt = YoutubeDL()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/youtube_dl/YoutubeDL.py", line 231, in __init__
    and not params['restrictfilenames']):
KeyError: 'restrictfilenames'
>>>

The area of code where it occurs is the following:

        if (sys.version_info >= (3,) and sys.platform != 'win32' and
                sys.getfilesystemencoding() in ['ascii', 'ANSI_X3.4-1968']
                and not params['restrictfilenames']):
            # On Python 3, the Unicode filesystem API will throw errors (#1474)
            self.report_warning(
                'Assuming --restrict-filenames since file system encoding '
                'cannot encode all charactes. '
                'Set the LC_ALL environment variable to fix this.')
            self.params['restrictfilenames'] = True

in particular, the line reading and not params['restrictfilenames']):

Given that the result of this if statement is to set, the restrictfilenames attribute of the object to True, does it matter what the existing value of params is? My proposed solution is to just remove that part of the if statement. The only potential difference I can see to the existing behaviour is that it would emit a warning even if params['restrictfilenames'] were explicitly set to True. I will submit this as a pull request. Please let me know if you see any problem with this, or if you need more information.

Thanks,
George

dstftw added a commit that referenced this issue Oct 10, 2014
KeyError on initialising YoutubeDL in python3 #3910
@dstftw dstftw closed this Oct 10, 2014
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
2 participants
You can’t perform that action at this time.