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)
Code: Select all
Deluge accepted connection
asking hosts list
starting !
Thank you very much
Olbaïd