youtube-dl: overwritten class _request is not providing expected attributes (commit: 648dc53)
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 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.
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: 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.
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 20 (20 by maintainers)
Commits related to this issue
- [utils] fix Request compat wrapper breaking inheritance (fixes #32573) — committed to zdimension/youtube-dl by zdimension 8 months ago
- [compat] Rework compat for `method` parameter of `compat_urllib_request.Request` constructor * fixes #32573 * does not break `utils.HEADrequest` (eg) — committed to dirkf/youtube-dl by dirkf 5 months ago
- [compat] Rework compat for `method` parameter of `compat_urllib_request.Request` constructor * fixes #32573 * does not break `utils.HEADrequest` (eg) — committed to dirkf/youtube-dl by dirkf 5 months ago
- [bot] AutoMerging: merge all upstream's changes: * https://github.com/ytdl-org/youtube-dl: [YouTube] Fix `like_count` extraction using `likeButtonViewModel` * also fix various tests * TODO: check a... — committed to hellopony/youtube-dl by github-actions[bot] 5 months ago
Fixed in #32695: thanks for the test.
@dirkf it looks like applying this as a patch works fine. I didn’t change the commit of the submodule, but I can if needed. Currently it’s on be008e657d79832642e2158557c899249c9e31cd
https://github.com/LizardByte/Themerr-plex/pull/336/files
Great, I’ll put it through full testing.
@dirkf this change works!