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

dict comprehension: invalid syntax in Python2.6 #31600

Closed
dirkf opened this issue Feb 19, 2023 · 6 comments
Closed

dict comprehension: invalid syntax in Python2.6 #31600

dirkf opened this issue Feb 19, 2023 · 6 comments

Comments

@dirkf
Copy link
Contributor

dirkf commented Feb 19, 2023

> 

Traceback (most recent call last):
  File "/usr/bin/youtube-dl", line 9, in <module>
    load_entry_point('youtube-dl==2021.12.17', 'console_scripts', 'youtube-dl')()
  File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 299, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 2229, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 1948, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.6/site-packages/youtube_dl/__init__.py", line 15, in <module>
    from .options import (
  File "/usr/lib/python2.6/site-packages/youtube_dl/options.py", line 8, in <module>
    from .downloader.external import list_external_downloaders
  File "/usr/lib/python2.6/site-packages/youtube_dl/downloader/__init__.py", line 23, in <module>
    from .niconico import NiconicoDmcFD
  File "/usr/lib/python2.6/site-packages/youtube_dl/downloader/niconico.py", line 11, in <module>
    from ..extractor.niconico import NiconicoIE
  File "/usr/lib/python2.6/site-packages/youtube_dl/extractor/__init__.py", line 9, in <module>
    from .extractors import *
  File "/usr/lib/python2.6/site-packages/youtube_dl/extractor/extractors.py", line 43, in <module>
    from .amara import AmaraIE
  File "/usr/lib/python2.6/site-packages/youtube_dl/extractor/amara.py", line 5, in <module>
    from .youtube import YoutubeIE
  File "/usr/lib/python2.6/site-packages/youtube_dl/extractor/youtube.py", line 23, in <module>
    from ..jsinterp import JSInterpreter
  File "/usr/lib/python2.6/site-packages/youtube_dl/jsinterp.py", line 265
    counters = {k: 0 for k in _MATCHING_PARENS.values()}
                       ^
SyntaxError: invalid syntax

Originally posted by @s1sw4nto in #31530 (comment)

@dirkf
Copy link
Contributor Author

dirkf commented Feb 19, 2023

Oops.

--- old/youtube-dl/youtube_dl/jsinterp.py
+++ new/youtube-dl/youtube_dl/jsinterp.py
@@ -262,7 +262,7 @@
         if not expr:
             return
         # collections.Counter() is ~10% slower in both 2.7 and 3.9
-        counters = {k: 0 for k in _MATCHING_PARENS.values()}
+        counters = dict((k, 0) for k in _MATCHING_PARENS.values())
         start, splits, pos, delim_len = 0, 0, 0, len(delim) - 1
         in_quote, escaping, skipping = None, False, 0
         after_op, in_regex_char_group, skip_re = True, False, 0

On the other hand we've found a Python 2.6 user at last. Any more takers?

@dirkf dirkf closed this as completed in 57802e6 Feb 19, 2023
@s1sw4nto
Copy link

s1sw4nto commented Feb 19, 2023

Traceback (most recent call last):
  File "/usr/bin/youtube-dl", line 9, in <module>
    load_entry_point('youtube-dl==2021.12.17', 'console_scripts', 'youtube-dl')()
  File "/usr/lib/python2.6/site-packages/youtube_dl/__init__.py", line 475, in main
    _real_main(argv)
  File "/usr/lib/python2.6/site-packages/youtube_dl/__init__.py", line 465, in _real_main
    retcode = ydl.download(all_urls)
  File "/usr/lib/python2.6/site-packages/youtube_dl/YoutubeDL.py", line 2081, in download
    url, force_generic_extractor=self.params.get('force_generic_extractor', False))
  File "/usr/lib/python2.6/site-packages/youtube_dl/YoutubeDL.py", line 801, in extract_info
    if not ie.suitable(url):
  File "/usr/lib/python2.6/site-packages/youtube_dl/extractor/common.py", line 415, in suitable
    cls._VALID_URL_RE = re.compile(cls._VALID_URL)
  File "/usr/lib64/python2.6/re.py", line 190, in compile
    return _compile(pattern, flags)
  File "/usr/lib64/python2.6/re.py", line 245, in _compile
    raise error, v # invalid expression
sre_constants.error: nothing to repeat

Not fixed, please check again, tell me if was update, I will update again

@dirkf
Copy link
Contributor Author

dirkf commented Feb 19, 2023

Unfortunately this doesn't finger whatever the actual problem is. It looks like there is a regular expression syntax issue for some Py <2.7.18 (possibly also in #31597).

Are you able to debug the problem?

If you have git it's probably easiest to check out the code in a user directory as described in the development section of the Manual. Otherwise you could work on the installed code as superuser.

  1. Add this line to youtube_dl/init.py (youtube_dl/__init__.py in the source):
--- old/youtube-dl/youtube_dl/__init__.py
+++ new/youtube-dl/youtube_dl/__init__.py
@@ -458,6 +458,7 @@
                 'You must provide at least one URL.\n'
                 'Type youtube-dl --help to see a list of all options.')
 
+        import pdb; pdb.set_trace()
         try:
             if opts.load_info_filename is not None:
                 retcode = ydl.download_with_info_file(expand_path(opts.load_info_filename))
  1. Run the test again. The debugger will break at the new line. Set a breakpoint at youtube_dl/extractor/common.py, line 415 (debugger syntax). Set a command to display cls and possibly cls._VALID_URL[:20] at that breakpoint. Continue, mindlessly, until you find the faulty extractor.

  2. Report back!

Meanwhile I have a Python 2.7.1 that I can test on later.

@dirkf dirkf reopened this Feb 19, 2023
@dirkf
Copy link
Contributor Author

dirkf commented Feb 20, 2023

And yes, it is the problem that I mentioned: #31597 (comment).

I'll close this in favour of #31597 since the original error reported was cleared.

@dirkf dirkf closed this as completed Feb 20, 2023
@s1sw4nto
Copy link

s1sw4nto commented Feb 20, 2023

#31600 (comment)

Finally I try iget update python from epel release and found python3.4 success installed.
Before that I try compile from official python website but no luck, python installed but pip get problem.
For now youtube-dl run normaly on my VPS Centos 6.10
Tnanks for advance.


yum --disablerepo="" --enablerepo="epel" list python3
yum --enablerepo=epel install python34.x86_64

curl -O https://bootstrap.pypa.io/pip/3.4/get-pip.py
python3.4 get-pip.py

pip install git+https://github.com/ytdl-org/youtube-dl.git@master#egg=youtube_dl

which python
ls -lh /usr/bin/python*

update-alternatives --install /usr/bin/python python /usr/bin/python3.4 1
update-alternatives --install /usr/bin/python python /usr/bin/python2.6 2

update-alternatives --display python
update-alternatives --config python

@dirkf
Copy link
Contributor Author

dirkf commented Feb 20, 2023

The current git master including commit 6067451 fixes #31597 and should work on your original Python 2.6.2 installation. I'd be interested if you were able to test it; on the other hand if you're going to stay on 3.4 we can wipe off the only known 2.6 user.

Actually, we don't have any easy way of testing 2.6, so it's supported in a slightly half-hearted way, by doing what should be the right thing in the code with compatibility shims and work-around expressions like the above fix.

In case 3.4 isn't good enough for you:

alxlive pushed a commit to alxlive/youtube-dl that referenced this issue Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants