Can't get rest api to work on 3.3

Linux specific questions, problems.
Post Reply
dsm1212

Can't get rest api to work on 3.3

Post by dsm1212 »

I've been running a 3.2 alpha build and I have some scripts to hit the rest api. I just can't get them to work on the latest code base using wget or curl. All I ever get is 403 Forbidden. For example, this small python routine works on 3.2alpha but not on 3.3. Did something change with authentication on 3.3 already?

thanks!

from lib import requests
from lib.requests.auth import HTTPDigestAuth

response = requests.get('http://192.168.1.200:7097/query/preferences', auth=HTTPDigestAuth('user','password'))
if not response.ok:
    response.raise_for_status()
print response.content
dsm1212

Re: Can't get rest api to work on 3.3

Post by dsm1212 »

Well I don't know why that approach is failing now but a simple curl to get a cookie works so I switched to that approach. For those that want it here's a bash script to send commands. Use it like this:

qbapi URLCOMMAND [POSTDATA]

For example:

$ qbapi command/resumeAll
$ qbapi command/setPreferences "{\"proxy_ip\"=\"1.2.3.4\"}"
$ qbapi query/torrents

----- Change user/pass/server/port and save this as qbapi and chmod +x the file -----
#!/bin/bash

# VARIABLES
user="admin"
password="xxxxxx"
server="1.2.3.4"
port="8080"

# Get a login cookie
COOKIE=`/usr/bin/curl -vs --data username=${user}\&password=${password} http://${server}:${port}/login 2>&1 | grep "SID=" | tr ';' ' ' | awk '{print $3}'`

cmd=$1
post=$2

if [ "$post" != "" ]; then
        post="--data ${post}"
fi

/usr/bin/curl -s --cookie "${COOKIE}" ${post} http://$server:$port/$cmd
Post Reply