Originally Posted by pan64
os.system("qdbus org.ktorrent.ktorrent /settings setPort [%s] : qdbus org.ktorrent.ktorrent /settings apply" % ( resp["port"] ))
but I'm not really sure. What is the desired command?
Thank you but its still not doing what I want.
Its not imputing the result of the python script to the command and my ktorrent port is coming out to 0.
Here is the full python script(which works perfectly without my extra part):
# put your VPN username and password below
YOUR_USERNAME = "xxxxx"
YOUR_PASSWORD = "xxxxx"
# This should be a long random string, or something that no one else is going
# to be able to guess. Don't share this amongst multiple computers on the
# same VPN account. If you have more than one computer, use a different client
# ID for each. I recommende the output of the Linux "uuidgen" command, but
# you can really just use whatever.
YOUR_CLIENT_ID = "xxxxx"
# The interface your VPN uses. We use this to look up your local IP, as
# required by the port forwarding API. Probably you won't have to change this
# unless you really know what you're doing (e.g., if you have more than one
# VPN tunnel on the same system or something)
VPN_IFACE = "tun0"
# This is the API URL. Don't change this.
API_URL = "https://www.privateinternetaccess.com/vpninfo/port_forward_assignment"
# Look up the local IP from the VPN interface
local_ip = netifaces.ifaddresses(VPN_IFACE)[netifaces.AF_INET]["addr"]
print "No such interface. Are you connected?"
# Make the API request to the webserver
request = urllib2.Request(API_URL, urllib.urlencode(
# Gather the (possibly multi-line) JSON response and create a python dict
# out of it
response = ""
for line in urllib2.urlopen(request).readlines():
response += line
resp = json.loads(response)
# Now either print out the forwarded port or an error message.
if "port" in resp:
os.system("qdbus org.ktorrent.ktorrent /settings setPort [%s] ; qdbus org.ktorrent.ktorrent /settings apply" % ( resp["port"] ))
elif "error" in resp:
print "Error: %s" % resp["error"]
print "Error: no idea what failed!"
After I run this python scrip without my line added, I get a number for my port. I can either enter it manualy within ktorrent or use the commands:
$ qdbus org.ktorrent.ktorrent /settings setPort (number I get from python script)
$ qdbus org.ktorrent.ktorrent /settings apply
thanks to Diantre.
I want to have this command run automatically within the python script.