overwritten class _request is not providing expected attributes (commit: 648dc53) #26683

Open
opened 2026-02-21 14:26:07 -05:00 by deekerman · 0 comments
Owner

Originally created by @ReenigneArcher on GitHub (Sep 27, 2023).

Checklist

  • I'm asking a question
  • I've looked through the README and FAQ for similar questions
  • I've searched the bugtracker for similar questions including closed ones

Question

WRITE QUESTION HERE

Starting with commit github.com/ytdl-org/youtube-dl@648dc5304c I am unable to use youtube-dl in my Plex plugin.

The traceback I get in the Plex plugin logs is not all that useful.

2023-09-28 02:27:26,494 (7f9dd1ce3808) :  CRITICAL (core:615) - Exception starting plug-in (most recent call last):
  File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/core.py", line 608, in start
    self.sandbox.execute(self.init_code)
  File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 256, in execute
    exec(code) in self.environment
  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Themerr-plex.bundle/Contents/Code/__init__.py", line 192, in <module>
    class Themerr(Agent.Movies):
  File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/agentkit.py", line 1133, in __new__
    AgentKit._register_agent_class(cls)
  File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/agentkit.py", line 1116, in _register_agent_class
    cls._shared_instance._push_agent_info()
  File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/agentkit.py", line 944, in _push_agent_info
    agent_info = agents
  File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/messaging.py", line 86, in call_external_function
    packed_result = self._core.networking.http_request(url, cacheTime=0, timeout=None, immediate=True).content
  File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/networking.py", line 352, in http_request
    return HTTPRequest(self._core, url, data, h, url_cache, encoding, errors, timeout, immediate, sleep, opener, follow_redirects, method)
  File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/networking.py", line 119, in __init__
    self.load()
  File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/networking.py", line 159, in load
    f = self._opener.open(req, timeout=self._timeout)
  File "/usr/lib/plexmediaserver/Resources/Python/python27.zip/urllib2.py", line 421, in open
    protocol = req.get_type()
  File "/usr/lib/plexmediaserver/Resources/Python/python27.zip/urllib2.py", line 280, in get_type
    if self.type is None:
  File "/usr/lib/plexmediaserver/Resources/Python/python27.zip/urllib2.py", line 254, in __getattr__
    raise AttributeError, attr
AttributeError: type

Given the code from the commit:

try:
    _req = compat_urllib_request.Request
    _req('http://127.0.0.1', method='GET')
except TypeError:
    class _request(object):
        def __new__(cls, url, *args, **kwargs):
            method = kwargs.pop('method', None)
            r = _req(url, *args, **kwargs)
            if method:
                r.get_method = types.MethodType(lambda _: method, r)
            return r

    compat_urllib_request.Request = _request

I'm assuming that the TypeError path will be taken in Python 2.7? And given that the overwritten _request object has no Attribute type which urllib2 seems to be expecting.

This is the last piece of code from the Plex framework before the builtins are called: github.com/squaresmile/Plex-Plug-Ins@fc4ab34d4c/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/networking.py (L159)

It's difficult to follow the framework code, but I believe this is function from the Plex framework being called by the line in the traceback. github.com/squaresmile/Plex-Plug-Ins@fc4ab34d4c/Framework.bundle/Contents/Resources/Versions/0/Python/PMS/HTTP.py (L119-L148)

I'm not 100% sure, but I'm thinking this could be considered a bug in youtube-dl IF it's overwriting built-in types.

Originally created by @ReenigneArcher on GitHub (Sep 27, 2023). <!-- ###################################################################### WARNING! IGNORING THE FOLLOWING TEMPLATE WILL RESULT IN ISSUE CLOSED AS INCOMPLETE ###################################################################### --> ## Checklist <!-- Carefully read and work through this check list in order to prevent the most common mistakes and misuse of youtube-dl: - Look through the README (http://yt-dl.org/readme) and FAQ (http://yt-dl.org/faq) for similar questions - Search the bugtracker for similar questions: http://yt-dl.org/search-issues - Finally, put x into all relevant boxes (like this [x]) --> - [x] I'm asking a question - [x] I've looked through the README and FAQ for similar questions - [x] I've searched the bugtracker for similar questions including closed ones ## Question <!-- Ask your question in an arbitrary form. Please make sure it's worded well enough to be understood, see https://github.com/ytdl-org/youtube-dl#is-the-description-of-the-issue-itself-sufficient. --> WRITE QUESTION HERE Starting with commit https://github.com/ytdl-org/youtube-dl/commit/648dc5304cb2476592ff142988b8c62675011fcc I am unable to use youtube-dl in my Plex plugin. The traceback I get in the Plex plugin logs is not all that useful. ```txt 2023-09-28 02:27:26,494 (7f9dd1ce3808) : CRITICAL (core:615) - Exception starting plug-in (most recent call last): File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/core.py", line 608, in start self.sandbox.execute(self.init_code) File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 256, in execute exec(code) in self.environment File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Themerr-plex.bundle/Contents/Code/__init__.py", line 192, in <module> class Themerr(Agent.Movies): File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/agentkit.py", line 1133, in __new__ AgentKit._register_agent_class(cls) File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/agentkit.py", line 1116, in _register_agent_class cls._shared_instance._push_agent_info() File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/agentkit.py", line 944, in _push_agent_info agent_info = agents File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/messaging.py", line 86, in call_external_function packed_result = self._core.networking.http_request(url, cacheTime=0, timeout=None, immediate=True).content File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/networking.py", line 352, in http_request return HTTPRequest(self._core, url, data, h, url_cache, encoding, errors, timeout, immediate, sleep, opener, follow_redirects, method) File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/networking.py", line 119, in __init__ self.load() File "/usr/lib/plexmediaserver/Resources/Plug-ins-1cf77d501/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/networking.py", line 159, in load f = self._opener.open(req, timeout=self._timeout) File "/usr/lib/plexmediaserver/Resources/Python/python27.zip/urllib2.py", line 421, in open protocol = req.get_type() File "/usr/lib/plexmediaserver/Resources/Python/python27.zip/urllib2.py", line 280, in get_type if self.type is None: File "/usr/lib/plexmediaserver/Resources/Python/python27.zip/urllib2.py", line 254, in __getattr__ raise AttributeError, attr AttributeError: type ``` Given the code from the commit: ```py try: _req = compat_urllib_request.Request _req('http://127.0.0.1', method='GET') except TypeError: class _request(object): def __new__(cls, url, *args, **kwargs): method = kwargs.pop('method', None) r = _req(url, *args, **kwargs) if method: r.get_method = types.MethodType(lambda _: method, r) return r compat_urllib_request.Request = _request ``` I'm assuming that the `TypeError` path will be taken in Python 2.7? And given that the overwritten `_request` object has no Attribute `type` which urllib2 seems to be expecting. This is the last piece of code from the Plex framework before the builtins are called: https://github.com/squaresmile/Plex-Plug-Ins/blob/fc4ab34d4cb995668abd84b304b57c5bf13cb69d/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/networking.py#L159 It's difficult to follow the framework code, but I believe this is function from the Plex framework being called by the line in the traceback. https://github.com/squaresmile/Plex-Plug-Ins/blob/fc4ab34d4cb995668abd84b304b57c5bf13cb69d/Framework.bundle/Contents/Resources/Versions/0/Python/PMS/HTTP.py#L119-L148 I'm not 100% sure, but I'm thinking this could be considered a bug in youtube-dl IF it's overwriting built-in types.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/youtube-dl-ytdl-org#26683
No description provided.