I’ve encountered something pretty strange. When I set the data field for HTTP.Request, the request loads early, without the specified body. If I don’t set data, or I set it to an empty string, it initializes as expected, and doesn’t load until I call request.load() later as it should. The weirder part is I set data in a different request elsewhere and it doesn’t load prematurely.
request = HTTP.Request(
OAUTHURL,
data = 'auth data here'
)
try:
request.load()
token = JSON.ObjectFromString(request.content)
2018-09-28 16:16:52,208 (700009d41000) : DEBUG (networking:166) - Requesting 'https://kitsu.io/api/oauth/token'
2018-09-28 16:16:53,256 (700009d41000) : ERROR (networking:219) - Error opening URL 'https://kitsu.io/api/oauth/token'
2018-09-28 16:16:53,257 (700009d41000) : CRITICAL (agentkit:1014) - Exception in the search function of agent named 'Kitsu', called with keyword arguments {'openSubtitlesHash': '96518cf312653bd8', 'episode': '1', 'episodic': '1', 'show': 'Cowboy Bebop', 'season': '1', 'filename': '%2FUsers%2FMatthew%2FDownloads%2FPlex%2FCowboy%20Bebop%2F1%2Emp4', 'plexHash': '997b5a78c7a8cbc7ae3f0d1b80f60a418462a901', 'duration': '140054', 'id': '145'} (most recent call last):
File "/Applications/Plex Media Server.app/Contents/Resources/Plug-ins-21ab172de/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/agentkit.py", line 1007, in _search
agent.search(*f_args, **f_kwargs)
File "/Users/Matthew/Library/Application Support/Plex Media Server/Plug-ins/Kitsu.bundle/Contents/Code/__init__.py", line 18, in search
search_anime('tv', results, media, lang)
File "/Users/Matthew/Library/Application Support/Plex Media Server/Plug-ins/Kitsu.bundle/Contents/Code/search.py", line 19, in search_anime
'X-Algolia-API-Key': algolia_key()
File "/Users/Matthew/Library/Application Support/Plex Media Server/Plug-ins/Kitsu.bundle/Contents/Code/kitsu.py", line 90, in algolia_key
return anon_key
File "/Users/Matthew/Library/Application Support/Plex Media Server/Plug-ins/Kitsu.bundle/Contents/Code/kitsu.py", line 21, in authenticate
return login(username, password)
File "/Users/Matthew/Library/Application Support/Plex Media Server/Plug-ins/Kitsu.bundle/Contents/Code/kitsu.py", line 42, in login
OAUTHURL,
File "/Applications/Plex Media Server.app/Contents/Resources/Plug-ins-21ab172de/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/networkkit.py", line 194, in Request
method=method,
File "/Applications/Plex Media Server.app/Contents/Resources/Plug-ins-21ab172de/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/networkkit.py", line 67, in _http_request
req = self._core.networking.http_request(url, *args, **kwargs)
File "/Applications/Plex Media Server.app/Contents/Resources/Plug-ins-21ab172de/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/networking.py", line 370, in http_request
return HTTPRequest(self._core, url, data, h, url_cache, encoding, errors, timeout, immediate, sleep, opener, follow_redirects, method)
File "/Applications/Plex Media Server.app/Contents/Resources/Plug-ins-21ab172de/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/networking.py", line 141, in __init__
self.load()
File "/Applications/Plex Media Server.app/Contents/Resources/Plug-ins-21ab172de/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/networking.py", line 181, in load
f = self._opener.open(req, timeout=self._timeout)
File "/Applications/Plex Media Server.app/Contents/Resources/Plug-ins-21ab172de/Framework.bundle/Contents/Resources/Platforms/Shared/Libraries/urllib2_new.py", line 444, in open
response = meth(req, response)
File "/Applications/Plex Media Server.app/Contents/Resources/Plug-ins-21ab172de/Framework.bundle/Contents/Resources/Platforms/Shared/Libraries/urllib2_new.py", line 557, in http_response
'http', request, response, code, msg, hdrs)
File "/Applications/Plex Media Server.app/Contents/Resources/Plug-ins-21ab172de/Framework.bundle/Contents/Resources/Platforms/Shared/Libraries/urllib2_new.py", line 482, in error
return self._call_chain(*args)
File "/Applications/Plex Media Server.app/Contents/Resources/Plug-ins-21ab172de/Framework.bundle/Contents/Resources/Platforms/Shared/Libraries/urllib2_new.py", line 416, in _call_chain
result = func(*args)
File "/Applications/Plex Media Server.app/Contents/Resources/Plug-ins-21ab172de/Framework.bundle/Contents/Resources/Platforms/Shared/Libraries/urllib2_new.py", line 565, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 401: Unauthorized
Elsewhere I have the following which works as expected
request = HTTP.Request(
'https://' + ALGOLIA_APP_ID + '-dsn.algolia.net/1/indexes/production_media/query',
headers = {
'Content-Type': 'application/json',
'X-Algolia-Application-Id': ALGOLIA_APP_ID,
'X-Algolia-API-Key': algolia_key()
},
data = '{"params":"query=' + query + '&facetFilters=[' + filters + ']"}'
)
try:
request.load()
Can anyone shed some light on this?
