Im trying to list out the torrents, but i cant seem to connect to the webui. The following code works fine with sickbeard and cp. Have any tried to accessing the webui with python? Is the webui using cookies aswell?
import urllib2
theurl = 'http://iptowebui:port'
username = 'x'
password = 'y'
# a great password
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
# this creates a password manager
passman.add_password(None, theurl, username, password)
# because we have put None at the start it will always
# use this username/password combination for urls
# for which `theurl` is a super-url
authhandler = urllib2.HTTPBasicAuthHandler(passman)
# create the AuthHandler
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
# All calls to urllib2.urlopen will now use our handler
# Make sure not to include the protocol in with the URL, or
# HTTPPasswordMgrWithDefaultRealm will be very confused.
# You must (of course) use it when fetching the page though.
pagehandle = urllib2.urlopen(theurl)
# authentication is now handled automatically for us
print pagehandle.read()
Accessing the webui
Re: Accessing the webui
I used this when playing around today.
Code: Select all
#!/usr/bin/env python
import httplib2, json
from django.utils.encoding import smart_str
h = httplib2.Http()
#user name and password for access to qBittorrent WebUI
h.add_credentials('username', 'password')
#Request the data for the torrents
content = h.request("http://127.0.0.1:8080/json/torrents")
#Decode the json string returned by the request use the second part
# of the returned request.
decode = json.loads(content[1])
#Rip through deoded data using smart_str from Django to handle some
# of the odd characters
for torrent in decode:
for key,value in torrent.items():
print(smart_str(key)+" => "+smart_str(value))
print("-"*48)