Page 1 of 1

[JSON API] "String indices must be integers" error

Posted: Fri Sep 28, 2012 8:10 am
by jacroe
I'm trying to add a local torrent file to Deluge using the web-ui's jsonRPC. I'm using this bit of code:

Code: Select all

curl -b cookies.txt --compressed -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"method":"web.add_torrents","params":[{"path":"/tmp/ubuntu-12.04.1-desktop-amd64.iso.torrent","options":null}],"id":1}' http://localhost:8081/json
And I'm getting a "String indices must be integers" error message. The error number is 3. How can I fix this?

Re: "String indices must be integers" error

Posted: Fri Sep 28, 2012 11:09 am
by Cas
It is because the method web.add_torrents can take multiple torrents so it is a list of dicts and when providing the params it is also a list so you require an extra pair of square brackets.

Code: Select all

curl -b cookies.txt --compressed -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"method":"web.add_torrents","params":[[{"path":"/tmp/ubuntu-12.04.1-desktop-amd64.iso.torrent","options":null}]],"id":1}' http://localhost:8081/json

Re: [JSON API] "String indices must be integers" error

Posted: Fri Sep 28, 2012 3:52 pm
by jacroe
Ah, thank you. I thought I had included enough brackets, but I suppose not. Thank you very much.