cgomesu / tvhlink

TVHlink (Tvheadend + Streamlink) integration
https://cgomesu.com/blog/Tvhlink
55 stars 8 forks source link

Streamlink install fails with error "AttributeError: module 'urllib3.util.url' has no attribute 'PERCENT_RE'. Did you mean: '_PERCENT_RE'?" #24

Closed JSDA123 closed 1 year ago

JSDA123 commented 1 year ago

Thank you for this useful script ... which was working just last week, however today fails when re-creating the container.

HTS Tvheadend 4.3-2120~g18effa8ad

Some more detail from the logs:

(46/47) Installing streamlink (5.4.0-r1)
(47/47) Installing streamlink-pyc (5.4.0-r1)
Executing busybox-1.35.0-r29.trigger
Executing ca-certificates-20230506-r0.trigger
OK: 434 MiB in 287 packages
Traceback (most recent call last):
  File "/usr/bin/streamlink", line 5, in <module>
    from streamlink_cli.main import main
  File "/usr/lib/python3.11/site-packages/streamlink_cli/main.py", line 15, in <module>
    import streamlink.logger as logger
  File "/usr/lib/python3.11/site-packages/streamlink/__init__.py", line 19, in <module>
    from streamlink.api import streams
  File "/usr/lib/python3.11/site-packages/streamlink/api.py", line 1, in <module>
    from streamlink.session import Streamlink
  File "/usr/lib/python3.11/site-packages/streamlink/session.py", line 15, in <module>
    from streamlink.plugin.api.http_session import HTTPSession
  File "/usr/lib/python3.11/site-packages/streamlink/plugin/api/__init__.py", line 1, in <module>
    from streamlink.plugin.api.http_session import HTTPSession
  File "/usr/lib/python3.11/site-packages/streamlink/plugin/api/http_session.py", line 52, in <module>
    class Urllib3UtilUrlPercentReOverride:
  File "/usr/lib/python3.11/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'?
[TVHlink] [info] Streamlink version: .
***********************************************
* Finished Streamlink install/upgrade script
* Message: Reached EOF without critical errors.
***********************************************
[custom-init] streamlink_for_tvh_container.sh: exited 0
cgomesu commented 1 year ago

hey, @JSDA123 , I've a couple of questions for you:

  1. are you using the latest version of the streamlink docker script?

  2. which container image are you running? (arm, amd, etc.)

please recreate the container and then copy and paste the entire log message here. (I need to see what it is trying to install and from which repo and that will show up in the beginning.)

JSDA123 commented 1 year ago

Thanks for the quick response!

I double-checked and am using the latest script.

The image is pulled from lscr.io/linuxserver/tvheadend:latest

"build_version": "Linuxserver.io version:- 18effa8a-ls162 Build-date:- 2023-05-06T15:45:37+00:00", "Architecture": "amd64"

The Log:

[custom-init] No custom services found, skipping...
[migrations] started
[migrations] no migrations found
───────────────────────────────────────

      ██╗     ███████╗██╗ ██████╗ 
      ██║     ██╔════╝██║██╔═══██╗
      ██║     ███████╗██║██║   ██║
      ██║     ╚════██║██║██║   ██║
      ███████╗███████║██║╚██████╔╝
      ╚══════╝╚══════╝╚═╝ ╚═════╝ 

   Brought to you by linuxserver.io
───────────────────────────────────────

To support LSIO projects visit:
https://www.linuxserver.io/donate/

───────────────────────────────────────
GID/UID
───────────────────────────────────────

User UID:    1000
User GID:    1000
───────────────────────────────────────

Setting permissions
[custom-init] Files found, executing
[custom-init] streamlink_for_tvh_container.sh: executing...
***********************************************
****** Streamlink install/upgrade script ******
***********************************************
Author: cgomesu
Repo: https://github.com/cgomesu/tvhlink
***********************************************
[TVHlink] [info] Installing/upgrading Streamlink...
fetch http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.17/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.17/community/x86_64/APKINDEX.tar.gz
(1/47) Upgrading musl (1.2.3-r4 -> 1.2.4-r0)
(2/47) Upgrading libcrypto3 (3.0.8-r4 -> 3.1.0-r4)
(3/47) Upgrading libssl3 (3.0.8-r4 -> 3.1.0-r4)
(4/47) Upgrading zlib (1.2.13-r0 -> 1.2.13-r1)
(5/47) Upgrading readline (8.2.0-r0 -> 8.2.1-r1)
(6/47) Upgrading libexpat (2.5.0-r0 -> 2.5.0-r1)
(7/47) Upgrading libbz2 (1.0.8-r4 -> 1.0.8-r5)
(8/47) Upgrading libffi (3.4.4-r0 -> 3.4.4-r2)
(9/47) Upgrading gmp (6.2.1-r2 -> 6.2.1-r3)
(10/47) Upgrading libgcc (12.2.1_git20220924-r4 -> 12.2.1_git20220924-r10)
(11/47) Upgrading libstdc++ (12.2.1_git20220924-r4 -> 12.2.1_git20220924-r10)
(12/47) Upgrading xz-libs (5.2.9-r0 -> 5.4.3-r0)
(13/47) Upgrading libxml2 (2.10.4-r0 -> 2.11.2-r0)
(14/47) Upgrading libgpg-error (1.46-r1 -> 1.47-r1)
(15/47) Upgrading libgcrypt (1.10.1-r0 -> 1.10.2-r1)
(16/47) Upgrading libxslt (1.1.37-r1 -> 1.1.38-r0)
(17/47) Upgrading sqlite-libs (3.40.1-r0 -> 3.41.2-r2)
(18/47) Upgrading gdbm (1.23-r0 -> 1.23-r1)
(19/47) Upgrading mpdecimal (2.5.1-r1 -> 2.5.1-r2)
(20/47) Upgrading python3 (3.10.11-r0 -> 3.11.3-r10)
(21/47) Installing python3-pycache-pyc0 (3.11.3-r10)
(22/47) Installing pyc (0.1-r0)
(23/47) Installing py3-certifi-pyc (2023.5.7-r0)
(24/47) Upgrading py3-charset-normalizer (3.0.1-r0 -> 3.1.0-r1)
(25/47) Installing py3-charset-normalizer-pyc (3.1.0-r1)
(26/47) Upgrading py3-idna (3.4-r2 -> 3.4-r4)
(27/47) Installing py3-idna-pyc (3.4-r4)
(28/47) Upgrading py3-urllib3 (1.26.12-r0 -> 2.0.2-r0)
(29/47) Installing py3-urllib3-pyc (2.0.2-r0)
(30/47) Installing py3-requests-pyc (2.30.0-r0)
(31/47) Installing python3-pyc (3.11.3-r10)
(32/47) Upgrading py3-certifi (2022.12.7-r0 -> 2023.5.7-r0)
(33/47) Upgrading py3-requests (2.28.1-r1 -> 2.30.0-r0)
(34/47) Installing py3-six (1.16.0-r6)
(35/47) Installing py3-six-pyc (1.16.0-r6)
(36/47) Installing py3-isodate (0.6.1-r4)
(37/47) Installing py3-isodate-pyc (0.6.1-r4)
(38/47) Installing py3-lxml (4.9.2-r4)
(39/47) Installing py3-lxml-pyc (4.9.2-r4)
(40/47) Installing py3-pycountry (22.3.5-r1)
(41/47) Installing py3-pycryptodome (3.17.0-r0)
(42/47) Installing py3-pysocks (1.7.1-r5)
(43/47) Installing py3-pysocks-pyc (1.7.1-r5)
(44/47) Installing py3-websocket-client (1.5.1-r1)
(45/47) Installing py3-websocket-client-pyc (1.5.1-r1)
(46/47) Installing streamlink (5.4.0-r1)
(47/47) Installing streamlink-pyc (5.4.0-r1)
Executing busybox-1.35.0-r29.trigger
Executing ca-certificates-20230506-r0.trigger
OK: 434 MiB in 287 packages
Traceback (most recent call last):
  File "/usr/bin/streamlink", line 5, in <module>
    from streamlink_cli.main import main
  File "/usr/lib/python3.11/site-packages/streamlink_cli/main.py", line 15, in <module>
    import streamlink.logger as logger
  File "/usr/lib/python3.11/site-packages/streamlink/__init__.py", line 19, in <module>
    from streamlink.api import streams
  File "/usr/lib/python3.11/site-packages/streamlink/api.py", line 1, in <module>
    from streamlink.session import Streamlink
  File "/usr/lib/python3.11/site-packages/streamlink/session.py", line 15, in <module>
    from streamlink.plugin.api.http_session import HTTPSession
  File "/usr/lib/python3.11/site-packages/streamlink/plugin/api/__init__.py", line 1, in <module>
    from streamlink.plugin.api.http_session import HTTPSession
  File "/usr/lib/python3.11/site-packages/streamlink/plugin/api/http_session.py", line 52, in <module>
    class Urllib3UtilUrlPercentReOverride:
  File "/usr/lib/python3.11/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'?
[TVHlink] [info] Streamlink version: .
***********************************************
* Finished Streamlink install/upgrade script
* Message: Reached EOF without critical errors.
***********************************************
[custom-init] streamlink_for_tvh_container.sh: exited 0
2023-05-10 12:43:55.616 [   INFO] main: Log started
2023-05-10 11:26:28.911 [   INFO] http: Starting HTTP server 0.0.0.0:9981
2023-05-10 11:26:28.911 [   INFO] htsp: Starting HTSP server 0.0.0.0:9982
2023-05-10 11:26:28.937 [   INFO] config: loaded
cgomesu commented 1 year ago

okay. I'll take a closer look at this issue over the weekend. in the meantime, you can try to manually install Streamlink via docker exec -it tvheadend sh to start a shell inside the running tvheadend container.

cgomesu commented 1 year ago
(28/47) Upgrading py3-urllib3 (1.26.12-r0 -> 2.0.2-r0)

this is likely the culprit. it is upgrading urllib3 to the latest (2.0+) version but streamlink is likely still using the more stable 1.26 one (see https://pypi.org/project/urllib3/#history for a version history). if this is the root of the issue, you should be able to fix it by downgrading py3-urllib3 back to 1.26.12-r0 or any available 1.26. this is a running theory at this point.

mhdsallal commented 1 year ago

I have exact same issue, it comes when update the latest community edition which updated yesterday fetch http://dl-cdn.alpinelinux.org/alpine/v3.17/community/x86_64/APKINDEX.tar.gz

image

mhdsallal commented 1 year ago
(28/47) Upgrading py3-urllib3 (1.26.12-r0 -> 2.0.2-r0)

this is likely the culprit. it is upgrading urllib3 to the latest (2.0+) version but streamlink is likely still using the more stable 1.26 one (see https://pypi.org/project/urllib3/#history for a version history). if this is the root of the issue, you should be able to fix it by downgrading py3-urllib3 back to 1.26.12-r0 or any available 1.26. this is a running theory at this point.

streamlink updated their library to support urllib3 2 https://github.com/streamlink/streamlink/commit/fac79a57427713e03ae82a36381e2d7e6510578e

cgomesu commented 1 year ago

streamlink updated their library to support urllib3 2 streamlink/streamlink@fac79a5

nice catch. it's related to this pr and it looks like it affects version 5.5 and up. this explains why version 5.4 in Alpine's edge is having trouble with urllib3 2.0.

this will probably get fixed as soon as the Alpine maintainer updates streamlink there but in the meantime, I'll see if I can find a quick fix for it other then manually downgrading urllib3.


recreating the container should also fix this:

***********************************************
****** Streamlink install/upgrade script ******
***********************************************
Author: cgomesu
Repo: https://github.com/cgomesu/tvhlink
***********************************************
[TVHlink] [info] Installing/upgrading Streamlink...
fetch http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.17/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.17/community/x86_64/APKINDEX.tar.gz
(1/47) Upgrading musl (1.2.3-r4 -> 1.2.4-r0)
(2/47) Upgrading libcrypto3 (3.0.8-r4 -> 3.1.0-r4)
(3/47) Upgrading libssl3 (3.0.8-r4 -> 3.1.0-r4)
(4/47) Upgrading zlib (1.2.13-r0 -> 1.2.13-r1)
(5/47) Upgrading readline (8.2.0-r0 -> 8.2.1-r1)
(6/47) Upgrading libexpat (2.5.0-r0 -> 2.5.0-r1)
(7/47) Upgrading libbz2 (1.0.8-r4 -> 1.0.8-r5)
(8/47) Upgrading libffi (3.4.4-r0 -> 3.4.4-r2)
(9/47) Upgrading gmp (6.2.1-r2 -> 6.2.1-r3)
(10/47) Upgrading libgcc (12.2.1_git20220924-r4 -> 12.2.1_git20220924-r10)
(11/47) Upgrading libstdc++ (12.2.1_git20220924-r4 -> 12.2.1_git20220924-r10)
(12/47) Upgrading xz-libs (5.2.9-r0 -> 5.4.3-r0)
(13/47) Upgrading libxml2 (2.10.4-r0 -> 2.11.2-r0)
(14/47) Upgrading libgpg-error (1.46-r1 -> 1.47-r1)
(15/47) Upgrading libgcrypt (1.10.1-r0 -> 1.10.2-r1)
(16/47) Upgrading libxslt (1.1.37-r1 -> 1.1.38-r0)
(17/47) Upgrading sqlite-libs (3.40.1-r0 -> 3.41.2-r2)
(18/47) Upgrading gdbm (1.23-r0 -> 1.23-r1)
(19/47) Upgrading mpdecimal (2.5.1-r1 -> 2.5.1-r2)
(20/47) Upgrading python3 (3.10.11-r0 -> 3.11.3-r11)
(21/47) Installing python3-pycache-pyc0 (3.11.3-r11)
(22/47) Installing pyc (0.1-r0)
(23/47) Installing py3-certifi-pyc (2023.5.7-r0)
(24/47) Upgrading py3-charset-normalizer (3.0.1-r0 -> 3.1.0-r1)
(25/47) Installing py3-charset-normalizer-pyc (3.1.0-r1)
(26/47) Upgrading py3-idna (3.4-r2 -> 3.4-r4)
(27/47) Installing py3-idna-pyc (3.4-r4)
(28/47) Upgrading py3-urllib3 (1.26.12-r0 -> 1.26.15-r2)
(29/47) Installing py3-urllib3-pyc (1.26.15-r2)
(30/47) Installing py3-requests-pyc (2.30.0-r0)
(31/47) Installing python3-pyc (3.11.3-r11)
(32/47) Upgrading py3-certifi (2022.12.7-r0 -> 2023.5.7-r0)
(33/47) Upgrading py3-requests (2.28.1-r1 -> 2.30.0-r0)
(34/47) Installing py3-six (1.16.0-r6)
(35/47) Installing py3-six-pyc (1.16.0-r6)
(36/47) Installing py3-isodate (0.6.1-r4)
(37/47) Installing py3-isodate-pyc (0.6.1-r4)
(38/47) Installing py3-lxml (4.9.2-r4)
(39/47) Installing py3-lxml-pyc (4.9.2-r4)
(40/47) Installing py3-pycountry (22.3.5-r1)
(41/47) Installing py3-pycryptodome (3.17.0-r0)
(42/47) Installing py3-pysocks (1.7.1-r5)
(43/47) Installing py3-pysocks-pyc (1.7.1-r5)
(44/47) Installing py3-websocket-client (1.5.1-r1)
(45/47) Installing py3-websocket-client-pyc (1.5.1-r1)
(46/47) Installing streamlink (5.4.0-r1)
(47/47) Installing streamlink-pyc (5.4.0-r1)
Executing busybox-1.35.0-r29.trigger
Executing ca-certificates-20230506-r0.trigger
OK: 434 MiB in 287 packages
[TVHlink] [info] Streamlink version: streamlink 5.4.0.
***********************************************
* Finished Streamlink install/upgrade script
* Message: Reached EOF without critical errors.
***********************************************
JSDA123 commented 1 year ago

It looks like this was fixed upstream, I can confirm Streamlink is successfully installed after recreating the container.

It's amazing how much I rely on this script, thanks again for providing it!

cgomesu commented 1 year ago

It looks like this was fixed upstream, I can confirm Streamlink is successfully installed after recreating the container.

It's amazing how much I rely on this script, thanks again for providing it!

Thanks for the follow up. Indeed, I've been trying to replicate the issue but it looks like py3-urllib3 version 2.0.2-r0 doesn't seem to be available anywhere in Alpine's repos anymore...

root@fd7b25f62f3c:/#apk add --no-cache -X "$APK_MAIN" -X "$APK_COMMUNITY" -X "$APK_TESTING" && apk info py3-urllib3
fetch http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.17/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.17/community/x86_64/APKINDEX.tar.gz
OK: 434 MiB in 287 packages
py3-urllib3-1.26.15-r2 description:
HTTP library with thread-safe connection pooling, file post, and more

py3-urllib3-1.26.15-r2 webpage:
https://github.com/urllib3/urllib3

py3-urllib3-1.26.15-r2 installed size:
572 KiB

py3-urllib3-1.26.12-r0 description:
HTTP library with thread-safe connection pooling, file post, and more

py3-urllib3-1.26.12-r0 webpage:
https://github.com/urllib3/urllib3

py3-urllib3-1.26.12-r0 installed size:
960 KiB

This is one of the dangers of installing from edge. Every once in a while we run into unstable changes. I think I'll have to take a closer look at the changes I added via #22 and find a more reliable implementation then installing from edge.