Page 1 of 1

Failed to upload torrent (web UI only)

Posted: Fri Jun 21, 2024 2:35 pm
by spurll
I'm running Deluge 2.1.1 on a headless Ubuntu server, adding torrents via the web UI (and flexget).

For the last week, whenever I attempt to upload a torrent file via the web UI, I get a pop-up error message that says "Failed to upload torrent".
Screenshot 1.png
Screenshot 1.png (9.3 KiB) Viewed 13253 times
When I attempt to add another torrent, the previously-added torrent file appears in the list as though it had been added, but with no options available.
Screenshot 2.png
Screenshot 2.png (27.28 KiB) Viewed 13253 times
Connecting to the server, no new torrent files have been added to the state directory.

Both deluged and deluge-web are running as systemd services under a dedicated deluge user.

When running deluged and deluge-web interactively in debug mode and trying to add a torrent, no errors, warnings, or other relevant messages appear.

I'm wondering if this is possibly a permissions problem or a Python versioning problem, but those are basically shots in the dark.

I have verified the following:
  • The same error messages appear on Vivaldi, Safari, and Edge
  • Attempting to upload a non-torrent file (e.g., a PNG) as a torrent I get the same message (so I suspect the file is not even making it to the server for verification)
  • Flexget is still able to add torrents
  • Using the web UI to add a torrent via a magnet link works fine
  • Directly transferring the torrent file to the server then adding it on the deluge console works fine
  • Connecting via a thin client to add a torrent via a torrent file works fine
System info:
deluge-web 2.1.1
deluged 2.1.1
libtorrent: 2.0.9.0
Python: 3.8.0
OS: Linux Ubuntu 18.04 bionic

Important notes:
  • I recently upgraded the system python3 from 3.6 to 3.8. (System python still points to 2.7.17.) I recall being able to add torrents via the web UI after the upgrade, though it's possible this issue is related and the system and services simply hadn't been rebooted
  • In an effort to fix the issue, I repeatedly uninstalled and reinstalled deluge via both apt and pip, which obviously didn't help. I have uninstalled everything and reinstalled deluge via apt (PPA)
  • I'm hoping that I don't have to upgrade Ubuntu to the latest LTS (I'm pretty busy and I'm hoping to defer that a couple months; I don't want to have to deal with the headache that this will involve), but if it has to happen I'll do it

Re: Failed to upload torrent (web UI only)

Posted: Fri Jun 21, 2024 10:43 pm
by ambipro
I think logs from deluge or deluge-web would be particularly useful in doing triage on this, if you can turn the logging on if it isn't already - possibly even debug if nothing shows up with standard INFO level, then reproduce this and post relevant logs with 10-15 lines before and after for good measure.

Re: Failed to upload torrent (web UI only)

Posted: Mon Jun 24, 2024 5:04 pm
by spurll
TL;DR: POSTing to the /upload endpoint is returning a 400 error, but nothing in the logs.

On info-level logging, I see no additional log items when I attempt to upload a torrent file.

Info-level logs for deluge-web:

Code: Select all

/usr/bin/deluge-web:6: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import load_entry_point
11:03:13 [INFO    ][deluge.ui.ui:68  ] Deluge ui 2.1.1
11:03:13 [INFO    ][deluge.ui.ui:70  ] Starting web ui..
11:03:13 [INFO    ][deluge.i18n.util           :101 ] Setting up translations from /var/lib/deluge/.local/lib/python3.8/site-packages/deluge/i18n
11:03:13 [INFO    ][deluge.ui.web.server       :731 ] Starting webui server at PID 19375
11:03:13 [INFO    ][deluge.ui.web.server       :746 ] Serving at http://0.0.0.0:8112/
11:03:36 [INFO    ][deluge.pluginmanagerbase   :189 ] Plugin Label enabled...
11:03:36 [INFO    ][deluge.pluginmanagerbase   :189 ] Plugin Scheduler enabled...
Info-level logs for deluged:

Code: Select all

/usr/bin/deluged:6: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import load_entry_point
11:03:04 [INFO    ][deluge.core.daemon            :91  ] Deluge daemon 2.1.1
11:03:04 [INFO    ][deluge.core.core              :334 ] Successfully loaded session.state: /var/lib/deluge/.config/deluge/session.state
11:03:04 [INFO    ][deluge.core.core              :334 ] Successfully loaded session.state: /var/lib/deluge/.config/deluge/session.state.bak
11:03:04 [INFO    ][deluge.core.alertmanager      :138 ] Alert Queue Size set to 10000
11:03:04 [INFO    ][deluge.core.rpcserver         :410 ] Starting DelugeRPC server :58846
11:03:04 [INFO    ][deluge.core.daemon            :151 ] Deluge daemon starting...
11:03:04 [WARNING ][deluge.core.preferencesmanager:465 ] GeoIP Unavailable: 'NoneType' object is not callable
11:03:04 [INFO    ][deluge_label.core             :78  ] *** Start Label plugin ***
11:03:04 [INFO    ][deluge.pluginmanagerbase      :189 ] Plugin Label enabled...
11:03:04 [INFO    ][deluge.pluginmanagerbase      :189 ] Plugin Scheduler enabled...
11:03:04 [INFO    ][deluge.core.authmanager       :224 ] Opening auth for load: /var/lib/deluge/.config/deluge/auth
11:03:04 [INFO    ][deluge.core.authmanager       :232 ] Successfully loaded auth: /var/lib/deluge/.config/deluge/auth
11:03:04 [INFO    ][deluge.core.torrentmanager    :811 ] Loading torrent state: /var/lib/deluge/.config/deluge/state/torrents.state
11:03:04 [INFO    ][deluge.core.torrentmanager    :824 ] Successfully loaded /var/lib/deluge/.config/deluge/state/torrents.state
11:03:04 [INFO    ][deluge.core.torrentmanager    :1071] Opening torrents.fastresume for load: /var/lib/deluge/.config/deluge/state/torrents.fastresume
11:03:04 [INFO    ][deluge.core.torrentmanager    :1082] Successfully loaded torrents.fastresume: /var/lib/deluge/.config/deluge/state/torrents.fastresume
11:03:04 [INFO    ][deluge.core.torrentmanager    :673 ] Torrent REDACTED from user "localclient" loaded
11:03:04 [INFO    ][deluge.core.torrentmanager    :673 ] Torrent REDACTED from user "flexget" loaded
11:03:04 [INFO    ][deluge.core.torrentmanager    :887 ] Finished loading 2 torrents in 0:00:00.290553
11:03:07 [INFO    ][deluge.core.rpcserver         :179 ] Deluge Client connection made from: 127.0.0.1:38460
11:03:07 [INFO    ][deluge.core.rpcserver         :179 ] Deluge Client connection made from: 127.0.0.1:38462
11:03:07 [INFO    ][deluge.core.rpcserver         :205 ] Deluge client disconnected: Connection to the other side was lost in a non-clean fashion: Connection lost.
11:03:07 [INFO    ][deluge.core.rpcserver         :205 ] Deluge client disconnected: Connection to the other side was lost in a non-clean fashion: Connection lost.
11:03:33 [INFO    ][deluge.core.rpcserver         :179 ] Deluge Client connection made from: 127.0.0.1:38556
11:03:33 [INFO    ][deluge.core.rpcserver         :179 ] Deluge Client connection made from: 127.0.0.1:38558
11:03:33 [INFO    ][deluge.core.rpcserver         :205 ] Deluge client disconnected: Connection to the other side was lost in a non-clean fashion: Connection lost.
11:03:33 [INFO    ][deluge.core.rpcserver         :205 ] Deluge client disconnected: Connection to the other side was lost in a non-clean fashion: Connection lost.
11:03:34 [INFO    ][deluge.core.rpcserver         :179 ] Deluge Client connection made from: 127.0.0.1:38634
11:03:34 [INFO    ][deluge.core.rpcserver         :179 ] Deluge Client connection made from: 127.0.0.1:38636
11:03:34 [INFO    ][deluge.core.rpcserver         :205 ] Deluge client disconnected: Connection to the other side was lost in a non-clean fashion: Connection lost.
11:03:34 [INFO    ][deluge.core.rpcserver         :205 ] Deluge client disconnected: Connection to the other side was lost in a non-clean fashion: Connection lost.
11:03:36 [INFO    ][deluge.core.rpcserver         :179 ] Deluge Client connection made from: 127.0.0.1:38640
11:03:36 [INFO    ][deluge.core.rpcserver         :205 ] Deluge client disconnected: Connection to the other side was lost in a non-clean fashion: Connection lost.
11:03:36 [INFO    ][deluge.core.rpcserver         :179 ] Deluge Client connection made from: 127.0.0.1:38644
When adding a torrent from the thin client, I get a log line as usual:

Code: Select all

11:07:57 [INFO    ][deluge.core.torrentmanager    :673 ] Torrent REDACTED from user "REDACTED" added
I repeated this exercise with debug-level logging and it's a constant deluge (sorry) of useless info, dozens of lines/second, but searching the logs I can see no reference to the file I attempted to add or any requests to the "upload" endpoint. (I can post these logs if it's truly helpful.)

However, I did notice that when I attempt to add the torrent file, there was actually an error that showed up in the browser console:

Code: Select all

POST IP_REDACTED:8112/upload 400 (Bad Request)
Failed to load resource: the server responded with a status of 400 (Bad Request)
It's been four years since my last web development job, so I'm quite rusty, but I guess it makes sense that a bad request wouldn't show up in the deluged logs, since it wouldn't actually hit be hitting the daemon, and if it's actually a malformed request I guess it wouldn't hit the deluge-web service either. Still don't understand what's wrong with the request, though (or why the server thinks there's something wrong with it).

Re: Failed to upload torrent (web UI only)

Posted: Tue Jun 25, 2024 7:55 am
by mhertz
Sorry dunno, but see you're still running a user pip install under deluge user(/'var/lib/deluge/.local/.....') - not that it should matter persay, but would myself clean everything and then use apt as you said, or pip, one or other, solely, and clean config.

Anyway, googling it states several web server issues with 400 error, bad port, missing permissions, to big request etc etc. Several reports on deluge too, where most unresolved sadly. I'd check in the webui debug log if the call looks right for the upload, and then i'd make a manual upload, with curl or alike, to see if can accept that or maybe get better error output, or something. We can help you with that, one of us, later. Btw, one docker user, with sounding same issue, magnets OK, not torrents, though docker, stated something about reverse proxy and iframes, maybe should look into dunno if only docker related though: https://github.com/binhex/arch-delugevp ... -569500379

Edit: Small old example I had laying around I use fo testing webUI in older time, though here for localhost:

Code: Select all

cookie=$(curl -v -H "Content-Type: application/json" -d '{"method": "auth.login", "params": ["deluge"], "id": 1}' http://localhost:8112/json 2>&1 | grep Cookie | cut -d':' -f2)
host=$(curl -H "cookie: $cookie" -H "Content-Type: application/json" -d '{"method": "web.get_hosts", "params": [], "id": 1}' http://localhost:8112/json | json_pp | tr -d " ", | grep -B 1 "127.0.0.1" | head -n1)
curl -H "cookie: $cookie" -H "Content-Type: application/json" -d '{"method": "web.connect", "params": ['$host'], "id": 1}' http://localhost:8112/json                                            
curl -H "cookie: $cookie" -H "Content-Type: application/json" -d '{"method": "web.add_torrents", "params": [[{"path":"/home/martin/testing/debian-11.6.0-amd64-netinst.iso.torrent", "options":null}]], "id": 1}' http://localhost:8112/json                                            
(Not the best at webUI as noticed, ambipro better :) )

Re: Failed to upload torrent (web UI only)

Posted: Wed Jun 26, 2024 12:32 pm
by mhertz
I'm sorry spurll, my example shell code I posted above you should ignore as won't work i'm affraid, sorry about that, I never tested web-UI API on other than locahost, so thought was same, but not - in short, the file-upload happens in javascript code and then the torrent is added to session with said web.add_torrents call, but as said is done with the temp file already uploaded(random named file saved under /tmp), and which then finally gets loaded in through core.add_torrent_file_async.

So, testing such cannot be done in shell script and deluge-web API alone i'm afraid. Instead "breakpoints" or how put - inserting prints of vars and calls etc, in the JS code itself, would be next step if was me - but it is almost surely not a deluge issue anyways, since works for everyone else, me included testing right now, so you should imho rather look elsewhere, e.g. webserver setup, permissions etc.

Sorry couldn't help better.

Re: Failed to upload torrent (web UI only)

Posted: Wed Jun 26, 2024 12:36 pm
by ambipro
mhertz wrote: Wed Jun 26, 2024 12:32 pm I'm sorry spurll, my example shell code I posted above you should ignore as won't work i'm affraid, sorry about that, I never tested web-UI API on other than locahost, so thought was same, but not - in short, the file-upload happens in javascript code and then the torrent is added to session with said web.add_torrents call, but as said is done with the temp file already uploaded, and which then finally gets loaded in through core.add_torrent_file_async.

So, testing such cannot be done in shell script and deluge-web API alone i'm afraid. Instead "breakpoints" or how put - inserting prints of vars and calls etc, in the JS code itself, would be next step if was me - but it is almost surely not a deluge issue anyways, since works for everyone else, me included testing right now, so you should imho rather look elsewhere, e.g. webserver setup, permissions etc.

Sorry couldn't help better.
I don't know if this would be making too much work for you, but using base64 encoding is relatively simple in python and you could use my class to do it, it would just require you to configure it and remove some of the unnecessary stuff, encode the file and then use the call function to add_torrent or whatever....

https://github.com/zakkarry/deluge-move ... e-mover.py

Re: Failed to upload torrent (web UI only)

Posted: Wed Jun 26, 2024 12:52 pm
by mhertz
Thanks bro, nice thinking there, but I don't think that would be necessary, but appreciate the thought, and lovely code for borrow, thanks! It's the javascript part that breaks unless i'm mistaken, so the upload to /tmp, before deluge calls that call and is most likely a personal setup issue of OP then. unless mistaken, but apologies in advance if off-base :)

If needed i'm guessing I can find and post where to insert console.log(foo) or alike, to troubleshoot further though, in the js code I mean.

Re: Failed to upload torrent (web UI only)

Posted: Wed Jun 26, 2024 3:30 pm
by spurll
Thanks, folks. I haven't had time to investigate further, but for now I've just swapped the deluge-web service to run the Python3.6 version again and it's working. I'm guessing there is maybe some package screwiness going on since the upgrade to Python 3.8. Once I get around to upgrading Ubuntu to the most recent LTS (which will come with a new system version of Python3) I'll revisit this, but for now it's working!

Re: Failed to upload torrent (web UI only)

Posted: Wed Jun 26, 2024 3:32 pm
by ambipro
There's a bunch of dependency issues going on behind the scenes affecting windows and mac users right now, wouldn't surprise me to see it elsewhere.

We're aware of the issue, downgrading and for some deps pinning a version is the current solution.

Re: Failed to upload torrent (web UI only)

Posted: Wed Jun 26, 2024 7:20 pm
by mhertz
Not important, but for own sake just wanting quickly correct myself in that it's not uploading in javascript code, but in twisted web-server part of deluge-web, so python code - deluge/ui/web/server.py, I'm not sure why webUI uploads torrents to server firstly, before adds with b64encoded payload as ambipro states, whereas gtk-UI thinclient doesn't, unless I misread code, quickly skimmed through, and noob, so take with grain of salt what I say.

Glad you got it workarounded atleast :)

Edit: Couldn't neither reproduce with python 3.8.0 and pip installed deluge.