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

AttributeError: module 'urllib3.util.url' has no attribute 'PERCENT_RE' #5324

Closed
4 tasks done
botbahlul opened this issue May 3, 2023 · 6 comments · Fixed by #5326
Closed
4 tasks done

AttributeError: module 'urllib3.util.url' has no attribute 'PERCENT_RE' #5324

botbahlul opened this issue May 3, 2023 · 6 comments · Fixed by #5326

Comments

@botbahlul
Copy link

botbahlul commented May 3, 2023

Checklist

Streamlink version

Latest stable release

Description

C:\Program Files\Python310\lib\site-packages\streamlink\plugin\api\http_session.py line 53 typo?

I was trying to run my script with python 3.10.4 in Windows 10 and got that error, but trying to run it with python 3.8.6 is working fine, why?

Debug log

File "C:\Program Files\Python310\lib\site-packages\streamlink\plugin\api\http_session.py", line 53, in Urllib3UtilUrlPercentReOverride
    _re_percent_encoding: Pattern = urllib3.util.url.PERCENT_RE  # type: ignore[attr-defined]
AttributeError: module 'urllib3.util.url' has no attribute 'PERCENT_RE'. Did you mean: '_PERCENT_RE'?
@botbahlul botbahlul added the bug label May 3, 2023
@bastimeyer
Copy link
Member

Streamlink applies an override for a faulty url encoding in urllib3, as you can see here:

Apparently, urllib3 has renamed its PERCENT_RE constant to _PERCENT_RE in its 2.0.0 release:
https://github.com/urllib3/urllib3/blame/2.0.0/src/urllib3/util/url.py#L15

On the 1.x branch, it's still PERCENT_RE:
https://github.com/urllib3/urllib3/blame/1.26.15/src/urllib3/util/url.py#L17

Streamlink does only support urllib3 1.x, so if you've installed urllib3 2.x in your python environment, then you're ignoring the dependency version constraints of streamlink and requests:

Not a bug. Fix your Streamlink install / python environment.

@bastimeyer bastimeyer added invalid user error Unrelated issues on the user's system and removed invalid labels May 3, 2023
@botbahlul
Copy link
Author

ok, thanks

@bastimeyer
Copy link
Member

Use a virtual environment if you have other packages in your python environment which depend on urllib3 2.x.
https://streamlink.github.io/install.html#virtual-environment

@bastimeyer bastimeyer changed the title http_session.py line 53 typo? AttributeError: module 'urllib3.util.url' has no attribute 'PERCENT_RE' May 3, 2023
@bastimeyer
Copy link
Member

So apparently requests has published version 2.30.0 with a bump to urllib3 <3:
https://github.com/psf/requests/releases/tag/v2.30.0

I unfortunately looked at the wrong package metadata yesterday. The right one is of course here:
https://github.com/psf/requests/blame/v2.30.0/setup.py#L64

They added a changelog just now after tagging the release yesterday already. For some reason, pip didn't pick up the new version for me when I ran pip install -U --upgrade-strategy=eager -r dev-requirements.txt -r docs-requirements.txt yesterday after seeing this thread here.


This means that Streamlink has to fix the new version incompabilities now.

I've restricted urllib3 to <2 for now in #5325, but I'm going to bump that to <3 again with the necessary changes.

This is a bit annoying, because requests should've bumped its major version in order to stay compliant with the semantic versioning scheme.

Speaking of semver, urllib3 isn't using this scheme correctly either, with lots of deprecations being added in 2.0.0, while stuff will get removed/changed in a minor release later on:
https://urllib3.readthedocs.io/en/stable/v2-migration-guide.html

So what needs to fix now is the name of the urllib3.utils.url._PATTERN_RE constant which Streamlink overrides, and maybe some other stuff which I'm going to look at now (TLS stuff / network interface stuff).

Reopening for visibility. Once fixed, there will be a new release, since the current stable release is broken when not limiting urllib3 to <2.

@bastimeyer bastimeyer reopened this May 4, 2023
@bastimeyer bastimeyer added dependencies and removed user error Unrelated issues on the user's system labels May 4, 2023
@bastimeyer
Copy link
Member

For some reason, pip didn't pick up the new version for me

They dropped 2.30.0 and re-released it today:
psf/requests#6432 (comment)

@bastimeyer
Copy link
Member

Fixed in 5.5.0
https://github.com/streamlink/streamlink/releases/tag/5.5.0

SteffenAuer added a commit to SteffenAuer/Youtube-Auto-Archiver that referenced this issue Aug 12, 2023
pzhlkj6612 added a commit to code-with-IPID/streamlink-plugins that referenced this issue Apr 17, 2024
AttributeError: module 'urllib3.util.url' has no attribute 'PERCENT_RE' · Issue #5324 · streamlink/streamlink
  streamlink/streamlink#5324

PEP 537 – Python 3.7 Release Schedule | peps.python.org
  https://peps.python.org/pep-0537/#lifespan
pmrowla pushed a commit to pmrowla/streamlink-plugins that referenced this issue Apr 26, 2024
…de" (#23)

* eplus: support account; refresh session within 15 mins; check "drm_mode"

"drm_mode" lives forever, while "drmEncryptKey" does not.

* eplus: code style

* eplus: pass extra params to EplusHLSStream via kwargs

* eplus: don't pass extra params to EplusHLSStream via kwargs

This partially reverts commit a8d50d2.

This is a Streamlink 6 feature (streamlink/streamlink@d593773). Don't be too radical.

* eplus: terminology! we are updating the session by refrshing cookies

* eplus: re-login account if required when refreshing cookies

* eplus: detect if cookies are invalidated; type annotations; clean code

* eplus: use "m3u8_urls" instead of "channel_urls"; clean code

If no stream_session, everything is dead.

* eplus: check if m3u8 url list is be parsed

* eplus: set up session updater during preparing streams

* eplus: allow empty m3u8 url list or empty stream session url

The Eplus DRM test page has neither list_channels nor the stream session.

* eplus: import streamlink.session.http.HTTPSession

* eplus: compatibility for Python<=3.10 and Streamlink<6.6.0

- https://peps.python.org/pep-0604/
- https://streamlink.github.io/deprecations.html#httpsession-and-httpadapters

* Streamlink 5.5.0 and Python 3.8 are required

AttributeError: module 'urllib3.util.url' has no attribute 'PERCENT_RE' · Issue #5324 · streamlink/streamlink
  streamlink/streamlink#5324

PEP 537 – Python 3.7 Release Schedule | peps.python.org
  https://peps.python.org/pep-0537/#lifespan

* eplus: hide the password in logs

* eplus: hide the email or the phone number in logs

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

Successfully merging a pull request may close this issue.

2 participants