24 lines
877 B
Python
24 lines
877 B
Python
from requests import post
|
|
from json import dumps
|
|
|
|
|
|
class I2PControl:
|
|
headers = {'content-type': 'application/json'}
|
|
|
|
def __init__(self, ip):
|
|
self.host = 'https://{}:7650'.format(ip)
|
|
|
|
def auth(self, password):
|
|
data = {'id': 0, 'jsonrpc': '2.0', 'method': 'Authenticate', 'params': {'API': 2, 'Password': password}}
|
|
self.token = post(self.host, data=dumps(data), headers=self.headers, verify=False).json()['result']['Token']
|
|
|
|
def request(self, method, params):
|
|
data = {'id': 0, 'jsonrpc': '2.0', 'method': method, 'params': params | {'Token': self.token}}
|
|
# required python 3.9
|
|
return post(self.host, data=dumps(data), headers=self.headers, verify=False).json()['result']
|
|
|
|
|
|
control = I2PControl('127.0.0.1')
|
|
control.auth('itoopie')
|
|
assert control.request('Echo', {'Echo': 'echo string'})['Result'] == 'echo string'
|