-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
overwritten class _request is not providing expected attributes (commit: 648dc53) #32573
Comments
(apparently it is necessary in the case above). The quoted compat code wraps the This is the context in urllib2.py: def open(self, fullurl, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
# accept a URL or a Request object
if isinstance(fullurl, basestring):
req = Request(fullurl, data)
else:
req = fullurl
if data is not None:
req.add_data(data)
req.timeout = timeout
protocol = req.get_type() # failing line
... As expected, it calls the def get_type(self):
if self.type is None:
self.type, self.__r_type = splittype(self.__original)
if self.type is None:
raise ValueError, "unknown url type: %s" % self.__original
return self.type Presumably the first line of the method is being resolved wrongly. The results of the commands |
A similar hack is already done at https://github.com/squaresmile/Plex-Plug-Ins/blob/fc4ab34d4cb995668abd84b304b57c5bf13cb69d/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/networking.py#L157, but this shouldn't be a problem. The Plex code appears to go straight into the original |
I'm not sure if this is possible as it's inside the Plex framework. As far as I know it's not really possible to run this on it's own outside of a Plex environment.
I'd guess that changes when I import youtube_dl? I'm not really that familiar with the source of youtube-dl or the compat layer... but I would be happy to test any patch/branch that may address this. |
Neither the code nor the backtrace from Plex shows any sign of calling yt-dl compat. As in another case recently the order of importing may be relevant. Try adding this missing attribute hook to the def __getattr__(self, name):
if hasattr(_req, name):
return _req.name
return super(_request, self).__getattr__(name) In case the lookup of attributes is not working, this should make the instance value default to the class value in the original |
I did remove the Adding this |
So there's something weirder going on. It looked familiar, and then I remembered utils.py l.2729
(I never found out why that worked, not having a Py2.6 at hand) So try this: def __new__(cls, url, *args, **kwargs):
method = kwargs.pop('method', None)
r = _req(url, *args, **kwargs)
+ r.get_type()
if method:
r.get_method = types.MethodType(lambda _: method, r)
return r |
Unfortunately, I get the same result. |
If you can't connect to the server where the Plex framework is running to use pdb, maybe you can hack some You could also try patching the failing line in urllib2: def get_type(self):
- if self.type is None:
+ if getattr(self, 'type', None) is None
self.type, self.__r_type = splittype(self.__original)
if self.type is None:
raise ValueError, "unknown url type: %s" % self.__original
return self.type This would have been safer in any case, even if it's difficult to see how |
I guess I could, but I have no idea where it would actually print to. There's no console or anything like that... I guess I could make it write some output to a specific file instead. I will try to get some additional output from the framework. I'm a bit confused as to what is wanted and where though. print(type(request))
print(dir(request)) |
I was thinking, just before https://github.com/python/cpython/blob/8d21aa21f2cbc6d50aab3f420bb23be1d081dac4/Lib/urllib2.py#L421. At that point the variable is What the BT does show is:
As some background, urllib2 "opens" a URL by calling a series of functions within the "opener", each dealing with a specific aspect of the opening task (proxies, cookies, ...) including one (that fails here) to open the network connection itself. |
Okay, I haven't got to this yet as it's not so easy to implement in my CI system. I looked into how plugins are loaded a little bit more, and it's quite interesting. They are loaded using I wonder if this has something to do with the errors. https://github.com/squaresmile/Plex-Plug-Ins/blob/master/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/loader.py |
xpython seems irrelevant: https://github.com/squaresmile/Plex-Plug-Ins/blob/master/Framework.bundle/Contents/Resources/Platforms/Shared/Libraries/xpython.py If it's using RestrictedPython, the version must be out of date, since v6 (2022) unsupported Python 2.7. But this is hardly the place to worry about that. If the sandbox policy messes with
|
@ReenigneArcher, if you could test this replacement code in --- old/youtube_dl/compat.py
+++ new/youtube_dl/compat.py
# Also fix up lack of method arg in old Pythons
try:
- _req = compat_urllib_request.Request
- _req('http://127.0.0.1', method='GET')
+ type(compat_urllib_request.Request('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
-
+ def _add_init_method_arg(cls):
+
+ init = cls.__init__
+
+ def wrapped_init(self, *args, **kwargs):
+ method = kwargs.pop('method', 'GET')
+ init(self, *args, **kwargs)
+ if self.has_data() and method == 'GET':
+ method = 'POST'
+ self.get_method = types.MethodType(lambda _: method, self)
+
+ cls.__init__ = wrapped_init
+
+ _add_init_method_arg(compat_urllib_request.Request)
+ del _add_init_method_arg |
@dirkf this change works! |
Great, I'll put it through full testing. |
…st.Request` constructor * fixes ytdl-org#32573 * does not break `utils.HEADrequest` (eg)
PR #32695 contains a similar fix, as in the above commit, and either could be tested. |
…st.Request` constructor * fixes ytdl-org#32573 * does not break `utils.HEADrequest` (eg)
This is not easy for me to test since it exists in a different repo and I am now using this as a submodule (due to no PyPi package) in my project... if you could make a branch in this repo, I could test it fairly easily. |
Maybe just apply commit 0c75367? |
@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 be008e6 https://github.com/LizardByte/Themerr-plex/pull/336/files |
Fixed in #32695: thanks for the test. |
* https://github.com/ytdl-org/youtube-dl: [YouTube] Fix `like_count` extraction using `likeButtonViewModel` * also fix various tests * TODO: check against yt-dlp tests [YouTube] Rework n-sig processing, realigning with yt-dlp * apply n-sig before chunked fragments, fixes ytdl-org#32692 [InfoExtractor] Support some warning and `._downloader` shortcut methods from yt-dlp [compat] Rework compat for `method` parameter of `compat_urllib_request.Request` constructor * fixes ytdl-org#32573 * does not break `utils.HEADrequest` (eg)
Checklist
Question
WRITE QUESTION HERE
Starting with commit 648dc53 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.
Given the code from the commit:
I'm assuming that the
TypeError
path will be taken in Python 2.7? And given that the overwritten_request
object has no Attributetype
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.
The text was updated successfully, but these errors were encountered: