idlesign / deluge-webapi

Plugin for Deluge WebUI providing sane JSON API
https://github.com/idlesign/deluge-webapi
BSD 3-Clause "New" or "Revised" License
120 stars 27 forks source link

Setting CORS is failing on python3.10 deluge2.1.1 with recent fix #36

Open JosephBrooksbank opened 2 years ago

JosephBrooksbank commented 2 years ago

Hi, I've been trying to get this plugin working to no avail. I saw that there was an issue with CORS that was fixed recently, so I built the egg myself from source on py3.10. I've enabled it and it shows in the webui, but enabling CORS and attempting to set allowed domains is failing with

11:21:52 [INFO    ][webapi.core                   :61  ] Patching webui for CORS...
11:21:52 [WARNING ][deluge.core.rpcserver         :246 ] An exception occurred while sending RPC_ERROR to client. Wrapping it and resending. Error to send(causing exception goes next):
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/deluge/core/rpcserver.py", line 334, in dispatch
    ret = self.factory.methods[method](*args, **kwargs)
  File "/config/plugins/WebAPI-0.4.0-py3.10.egg/webapi/core.py", line 47, in set_config
    self.patch_web_ui()
  File "/config/plugins/WebAPI-0.4.0-py3.10.egg/webapi/core.py", line 63, in patch_web_ui
    cmp_json = component.get('JSON')
  File "/usr/lib/python3.10/site-packages/deluge/component.py", line 486, in get
    return _ComponentRegistry.components[name]
KeyError: 'JSON'

11:21:52 [ERROR   ][deluge.core.rpcserver         :1512] Exception calling RPC request: 'JSON'
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/deluge/core/rpcserver.py", line 334, in dispatch
    ret = self.factory.methods[method](*args, **kwargs)
  File "/config/plugins/WebAPI-0.4.0-py3.10.egg/webapi/core.py", line 47, in set_config
    self.patch_web_ui()
  File "/config/plugins/WebAPI-0.4.0-py3.10.egg/webapi/core.py", line 63, in patch_web_ui
    cmp_json = component.get('JSON')
  File "/usr/lib/python3.10/site-packages/deluge/component.py", line 486, in get
    return _ComponentRegistry.components[name]
KeyError: 'JSON'

I can look at it more when I'm off work, but help would be appreciated

JosephBrooksbank commented 2 years ago

Looking into it more, it seems this issue is happening with 3.8 too, and the solution there is to turn off CORS, which isn't super helpful.

EDIT: Since I am still early into the project, to get around the CORS issue I simply moved frameworks to nextJS to implement a proxy API to hit deluge, since the backend doesn't respect CORS headers. All frontend requests go to /api/deluge, rather than to deluge_url/json directly.

idlesign commented 2 years ago

Hi,

KeyError: 'JSON'

The substantial thing here is to investigate the reason why Deluge's JSON component is not available is some cases.