Clean up rest client

This commit is contained in:
Matthias 2019-04-26 09:08:03 +02:00
parent a132d6e141
commit b0ac98a7cd

View File

@ -40,8 +40,8 @@ INFO_COMMANDS = {"version": [],
class FtRestClient(): class FtRestClient():
def __init__(self, serverurl): def __init__(self, serverurl):
self.serverurl = serverurl
self.serverurl = serverurl
self.session = requests.Session() self.session = requests.Session()
def call(self, method, apipath, params: dict = None, data=None, files=None): def call(self, method, apipath, params: dict = None, data=None, files=None):
@ -62,19 +62,17 @@ class FtRestClient():
url = urlunparse((schema, netloc, path, params, query, fragment)) url = urlunparse((schema, netloc, path, params, query, fragment))
print(url) print(url)
try: try:
resp = self.session.request(method, url, headers=hd, data=data,
req = requests.Request(method, url, headers=hd, data=data,
# auth=self.session.auth # auth=self.session.auth
) )
reqp = req.prepare() # return resp.text
return self.session.send(reqp).json() return resp.json()
# return requests.get(url).json()
except ConnectionError: except ConnectionError:
logger.warning("Connection error") logger.warning("Connection error")
def call_command_noargs(self, command): def call_command_noargs(self, command):
logger.info(f"Running command `{command}` at {self.serverurl}") logger.info(f"Running command `{command}` at {self.serverurl}")
r = self.call("GET", command) r = self.call("POST", command)
logger.info(r) logger.info(r)
def call_info(self, command, command_args): def call_info(self, command, command_args):