1.3.14 Cannot add url via json api

General support for problems installing or using Deluge
nosmokingbandit
New User
New User
Posts: 6
Joined: Mon Jan 23, 2017 8:43 pm
OS or Distro: Debian

1.3.14 Cannot add url via json api

Postby nosmokingbandit » Mon Mar 13, 2017 6:32 pm

Using 1.3.14 I can no longer submit a torrent url. With prior versions I would send a request to the json api similar to this:

torrent = {'path': 'www.torrentsite.com/file.torrent'}
command = {'method': 'web.add_torrents',
'params': [[torrent]],
'id': command_id
}
command_id += 1

request = urllib2.Request(web_ui_url, post_data=json.dumps(command))

However, now I get the error
invalid mode ('rb') or filename: u'www.torrentsite.com/file.torrent'

What is the preferred method to add torrents via url?

Cas
Top Bloke
Top Bloke
Posts: 3442
Joined: Mon Dec 07, 2009 6:04 am
OS or Distro: Ubuntu 16.04
Location: Scotland

Re: 1.3.14 Cannot add url via json api

Postby Cas » Mon Mar 13, 2017 9:43 pm

Are you setting the content header? See viewtopic.php?f=7&t=54428

nosmokingbandit
New User
New User
Posts: 6
Joined: Mon Jan 23, 2017 8:43 pm
OS or Distro: Debian

Re: 1.3.14 Cannot add url via json api

Postby nosmokingbandit » Wed Mar 15, 2017 9:37 pm

I am setting the header according to that thread. I can add magnet URIs fine, just not .torrent URLs.

The full(-ish) code I use is:

Code: Select all

        headers = {'Content-Type': 'application/json', 'User-Agent': 'Watcher'}
        url = 'http://localhost:8112/json'

        command = {'method': 'web.add_torrents',
                   'params': [[torrent]],
                   'id': DelugeWeb.command_id
                   }
        DelugeWeb.command_id += 1

        post_data = json.dumps(command)
        request = Url.request(url, post_data=post_data, headers=headers)
        request.add_header('cookie', DelugeWeb.cookie)  # This is taken care of elsewhere
        urllib2.urlopen(request)
       


And the output from Deluge is:

Code: Select all

[ERROR   ] 17:35:42 json_api:239 Error calling method `web.add_torrents`
[ERROR   ] 17:35:42 json_api:240 [Errno 22] invalid mode ('rb') or filename: u'http://www.indexer.com/this_is_a_torrent.torrent'
Traceback (most recent call last):
  File "deluge\ui\web\json_api.py", line 231, in _handle_request
  File "deluge\ui\web\json_api.py", line 198, in _exec_local
  File "deluge\ui\web\json_api.py", line 791, in add_torrents
IOError: [Errno 22] invalid mode ('rb') or filename: u'http://www.indexer.com/this_is_a_torrent.torrent'





This is for Watcher, btw. In case you are interested. https://github.com/nosmokingbandit/watcher

Cas
Top Bloke
Top Bloke
Posts: 3442
Joined: Mon Dec 07, 2009 6:04 am
OS or Distro: Ubuntu 16.04
Location: Scotland

Re: 1.3.14 Cannot add url via json api

Postby Cas » Wed Mar 15, 2017 11:30 pm

Ok with that log I see what you mean. You are using a URL for a file location, hence filename in error trace. See download_torrent_from_url

http://git.deluge-torrent.org/deluge/tr ... table#n653

Cas
Top Bloke
Top Bloke
Posts: 3442
Joined: Mon Dec 07, 2009 6:04 am
OS or Distro: Ubuntu 16.04
Location: Scotland

Re: 1.3.14 Cannot add url via json api

Postby Cas » Wed Mar 15, 2017 11:33 pm

There have been no changes to API though so not sure how it worked before for you.

nosmokingbandit
New User
New User
Posts: 6
Joined: Mon Jan 23, 2017 8:43 pm
OS or Distro: Debian

Re: 1.3.14 Cannot add url via json api

Postby nosmokingbandit » Fri Mar 17, 2017 1:29 am

Yeah, that fixed me up. Thanks for the help, much appreciated :D

With a cursory glance over the entire api it doesn't seem possible to download the url and load it into Deluge in one command. Am I being dumb again or is this not possible? Have you considered adding the ability to do this?

I know it can be super annoying when other people make suggestions on how to code things, but perhaps you can add a quick test in WebApi.add_torrents() that tests if the passed torrent is a URL or not, then executes download_torrent_from_url() and loads the return value directly into the download queue?

Insert after line 789

Code: Select all

if urlparse.urlparse(torrent['path']).scheme != "":
   torrent['path'] = self.download_torrent_from_url(torrent)



Not a huge deal, but you'd save the overhead of one extra api request per url download.


Return to “Support”

Who is online

Users browsing this forum: Jay-C and 18 guests