Page 1 of 1

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

Posted: Fri Dec 12, 2014 6:47 pm
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

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

Posted: Fri Dec 12, 2014 9:45 pm
by Cas
If you are using Python why are you not just using the Deluge API? http://dev.deluge-torrent.org/wiki/Development

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

Posted: Sat Dec 13, 2014 12:35 am
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 ^^ )

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

Posted: Sun Jan 25, 2015 3:55 pm
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.

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

Posted: Sun Jan 25, 2015 4:16 pm
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()