Page 1 of 1

Reading response from webui/json

Posted: Mon Jan 23, 2017 8:48 pm
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?

Re: Reading response from webui/json

Posted: Mon Jan 23, 2017 10:19 pm
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}

Re: Reading response from webui/json

Posted: Mon Jan 23, 2017 11:11 pm
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

Re: Reading response from webui/json

Posted: Mon Jan 23, 2017 11:48 pm
by Cas
It's gzip compressed...

Re: Reading response from webui/json

Posted: Tue Jan 24, 2017 12:43 am
by nosmokingbandit
Yeah, I'm kind of dumb.

Everything is working fine now. Thanks for the pointers.