def request(self, method, endpoint, body=None, timeout=-<NUM_LIT:1>):
if method not in set(['<STR_LIT:GET>', '<STR_LIT:POST>', '<STR_LIT>', '<STR_LIT>']):<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>url = '<STR_LIT:/>' + self.api_v + endpoint<EOL>headers = {<EOL>'<STR_LIT>': self.token,<EOL>'<STR_LIT:Content-Type>': '<STR_LIT:application/json>'<EOL>}<EOL>if body:<EOL><INDENT>json_body_or_None = json.dumps(body)<EOL><DEDENT>else:<EOL><INDENT>json_body_or_None = None<EOL><DEDENT>call_timeout = timeout if timeout != -<NUM_LIT:1> else self.timeout<EOL>APIcall = getattr(requests, method.lower())<EOL>res = APIcall('<STR_LIT>' + url,<EOL>data=json_body_or_None,<EOL>headers=headers,<EOL>timeout=call_timeout)<EOL>if res.text:<EOL><INDENT>res_json = res.json()<EOL><DEDENT>else:<EOL><INDENT>res_json = {}<EOL><DEDENT>return self.__error_middleware(res, res_json)<EOL>
Perform a request with a given body to a given endpoint in UpCloud's API.

Handles errors with __error_middleware.