Page 1 of 1
a simple script about making a Transmission RPC request wit
Posted: Sun Sep 04, 2011 3:00 am
by RK_py
Code: Select all
#!/usr/bin/env python
# encoding: utf-8
# a simple script about making an Transmission RPC request with python3
#!/usr/bin/python3
import http.client
import json
HOST = 'localhost' # The remote host
PATH = "/transmission/rpc/" # The path
PORT = 9091 # The same port as used by the server
URL = "http://%s:%s%s"%(HOST,PORT,PATH) # combined full url
TIMEOUT = 30
# retrieving session id
conn = http.client.HTTPConnection(HOST, PORT)
conn.request("GET", PATH)
response = conn.getresponse()
response_data = response.read()
response.close()
conn.close()
session_id = str(response_data).split("X-Transmission-Session-Id: ")[-1].split("</code></p>'")[0]
headers = {'x-transmission-session-id': str(session_id)}
# retrieving torrent list
fields = ['name', 'id']
query = json.dumps({'method': 'torrent-get', 'arguments': {'fields': fields}}).encode('utf-8')
conn = http.client.HTTPConnection(HOST, PORT)
conn.request("POST", PATH, query, headers)
response = conn.getresponse()
response_raw = response.read()
response.close()
conn.close()
response = json.loads(response_raw.decode("utf-8"))
print(json.dumps(response, indent=4))
I didn't know where to put this since I don't know how to access the wiki and submitting a ticket for it wasn't the right thing to do (
http://trac.transmissionbt.com/ticket/4467 ) ...
Good luck

R.K.
Re: a simple script about making a Transmission RPC request
Posted: Sun Sep 04, 2011 10:00 am
by blacke4dawn
Not sure what this is supposed to do but if this is supposed to be a generic RPC interface then I think it would be better if you gave your support to
http://pypi.python.org/pypi/transmissionrpc/ by making that usable on the 3.X series.
Re: a simple script about making a Transmission RPC request
Posted: Sun Sep 04, 2011 8:56 pm
by RK_py
"a generic RPC interface" is just about right. The thing is, it's such a trivial matter to implement the transmission json-rpc once you know what your doing, that writing a wrapper around it and maintaining it with each version change is simply an overkill. Only reason to write such a module is if you're aiming at writing an entire gui around it. which I'm not. why, just those few lines I wrote can be made into a function or two that will cover all possible requests.

Re: a simple script about making a Transmission RPC request
Posted: Mon Sep 05, 2011 12:52 pm
by blacke4dawn
You say can be made as in it needs a bit of modification?
Well, the TransmissionRPC module aims at providing everything you may need when communicating with Transmission without any to modify it. So in the end you either copy paste your functions and modify them to what you want to do or you just import another module which already does what you need. Honestly, outside of Python 3.X support I don't really see the benefit of it.
I'm not against it per say but the biggest benefit in my opinion in using third-party modules is that you don't really need to get to know every intricate detail about everything that you touch upon in your project. I'm sure someone, besides you, will find this useful however I also think that the collected efforts on as few implementations of "generic interfaces" is the optimal route.