Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#4467 closed Enhancement (invalid)

A simple python3 example script I wish to contribute

Reported by: RK_py Owned by:
Priority: Low Milestone:
Component: Transmission Version: 2.33
Severity: Trivial Keywords: python3 example script
Cc:

Description (last modified by jordan)

#!/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))

Attachments (1)

transmission.py (1.2 KB) - added by RK_py 10 years ago.
a simple script about making an Transmission RPC request with python3

Download all attachments as: .zip

Change History (5)

Changed 10 years ago by RK_py

a simple script about making an Transmission RPC request with python3

comment:1 Changed 10 years ago by jordan

  • Description modified (diff)

comment:2 Changed 10 years ago by jordan

  • Resolution set to invalid
  • Status changed from new to closed

Thank you for submitting this, but I'm not sure what you want the development team to do with it.

This probably should be posted in the forums rather than in the bug tracker.

Thanks though!

comment:3 Changed 10 years ago by jordan

  • Milestone Sometime deleted

comment:4 Changed 10 years ago by RK_py

While browsing the wiki trying to figure out how to use the rpc, I stumbled upon the python script in https://trac.transmissionbt.com/wiki/Scripts which doesn't use the rpc at all. After many trials and errors I figured how to get it done on my own, and so I decided to register and attach the script to the wiki. Unfortunately, once registering I didn't have access to editing the wiki, and not knowing about the forum, I guessed opening a ticket is the due course of action...

Don't suppose you can try adding it to the wiki ? I'm sure someone will find it useful someday. Thanks, R.K.

Note: See TracTickets for help on using tickets.