Reading response from webui/json

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

Reading response from webui/json

Post by nosmokingbandit »

I'm using python to connect to the web ui. I can log in fine, but if I supply an in correct password the response is always 'OK' as well, which isn't super helpful.

Code: Select all

	url = 'http://localhost:8112/json'

        command = {'method': 'auth.login',
                   'params': [password],
                   'id': command_id
                   }
        command_id += 1

        command = json.dumps(command)

        request = urllib2.Request(url, command, headers={'User-Agent': 'Mozilla/5.0'})

        try:
            response = urllib2.urlopen(request)
	[etc...]
The response.msg is *always* "OK". But I can see in my deluge-web stdout the message

Code: Select all

[ERROR   ] 23:37:05 auth:329 Login failed (ClientIP 123.456.789.876)
How can I get feedback from the json api to discern a bad password?
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Reading response from webui/json

Post by Cas »

I think you need to look again at what you are receiving because it's in the json response not the HTTP code:

Wrong password:

Code: Select all

HTTP/1.1 200 OK
...
{"id": 1, "result": false, "error": null}
Correct password:

Code: Select all

HTTP/1.1 200 OK
...
Set-Cookie: _session_id=43a214af5f059d07a939e131a3cef6cd2281 
{"id": 1, "result": true, "error": null}
nosmokingbandit
New User
New User
Posts: 6
Joined: Mon Jan 23, 2017 8:43 pm

Re: Reading response from webui/json

Post by nosmokingbandit »

I can get the cookie from the response header, but I can't find any json in the response.

If I do a basic response.read() I get something like this:

Code: Select all

      ½V╩LQ▓R0╨QP*J-.═)r≥JsrÇⁿ╘óóⁿ" ╖Z)7╡╕81=╚V≥╦/QH,-╔H═+╔LN,IMQ¬L╬OI╓╓ U8╖0O
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Reading response from webui/json

Post by Cas »

It's gzip compressed...
nosmokingbandit
New User
New User
Posts: 6
Joined: Mon Jan 23, 2017 8:43 pm

Re: Reading response from webui/json

Post by nosmokingbandit »

Yeah, I'm kind of dumb.

Everything is working fine now. Thanks for the pointers.
Post Reply