[JSON API] Need help can't get ALL torrents

Suggestions and discussion of future versions
Post Reply
olbaid
New User
New User
Posts: 5
Joined: Thu Jul 31, 2014 6:02 pm

[JSON API] Need help can't get ALL torrents

Post by olbaid »

Hi !

I've been strugling with the JSON API, trying to get every torrents in my program.
I'm so sorry if it's a stupid, it's my very first time with python. ^^

At this point, I have this code :

Code: Select all

import sys
sys.path.append("C:\\Users\\olbaid\\Documents\\python\\deluge\\SuperSeedboxClient\\server\\include")
import requests
import json

def sendJsonRequest(session, request, params, id, cookie=None):
	url = "http://127.0.0.1:8113/json"
	headers = {'content-type': 'application/json'}
	toSend = {
		"method": request,
		"params": params,
		"jsonrpc": "2.0",
		"id": id
	}
	return session.post(url, data=json.dumps(toSend), headers=headers)

def initSession():
	session = requests.Session()	
	res = sendJsonRequest(session, "auth.login", [""], 1).json()
	if(res["result"] == True):
		print("Deluge accepted connection")
		checkCo = sendJsonRequest(session, "web.connected", [], 2).json()
		if(checkCo["result"] == True):
			print("asking hosts list")
			hosts = sendJsonRequest(session, "web.get_hosts", [], 3).json()
			connected = sendJsonRequest(session, "web.connect", [hosts["result"][0][0]], 4).json()
			if(connected['error'] == None):
				return session
			else:
				print("ERROR INITIALIZING JSON INTERFACE")

s = initSession()
print("starting !")
[b]res = sendJsonRequest(s, "core.get_torrents_status", [], 10).json()[/b]
print(res)
But it keeps "buffering" after asking for the torrents :

Code: Select all

Deluge accepted connection
asking hosts list
starting !
Could anyone put me on the way ?

Thank you very much
Olbaïd
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Need help with Json API, can't get ALL torrents

Post by Cas »

If you are using Python why are you not just using the Deluge API? http://dev.deluge-torrent.org/wiki/Development
olbaid
New User
New User
Posts: 5
Joined: Thu Jul 31, 2014 6:02 pm

Re: Need help with Json API, can't get ALL torrents

Post by olbaid »

Couldn't figure how to use it, if not for a plugin. :?
( And I have problems importing deluge libraries on windows, but I'm working on it ^^ )
remuladgryta
New User
New User
Posts: 2
Joined: Sun Jan 25, 2015 3:42 pm

Re: Need help with Json API, can't get ALL torrents

Post by remuladgryta »

If you're going the JSON route, I'd recommend calling

Code: Select all

web.update_ui
instead of

Code: Select all

core.get_torrents_status
See this doc page for the json api methods.
remuladgryta
New User
New User
Posts: 2
Joined: Sun Jan 25, 2015 3:42 pm

Re: Need help with Json API, can't get ALL torrents

Post by remuladgryta »

Sorry for double posting, but I tried running your program and couldn't get it to work which is what led me to suggest web.update_ui as the more suitable option. However, after some further fiddling, I realized that the arguments to core.get_torrents_status weren't correctly specified. core.get_torrents_status takes two (optionally three) arguments, filter_dict and keys. it expects filter_dict to be a dictionary and keys to be a list of strings. I'm not sure what causes it to hang instead of responding with an error without proper arguments, but changing your line to the following works for me

Code: Select all

res = sendJsonRequest(s, "core.get_torrents_status", [{},[]], 10).json()
Post Reply