Open HackXIt opened 5 days ago
Provided files should also modify the behavior of:
def log_curl_debug(self, method, url, data=None, headers=None, level=logging.DEBUG):
"""
:param method:
:param url:
:param data:
:param headers:
:param level:
:return:
"""
headers = headers or self.default_headers
message = "curl --silent -X {method} -H {headers} {data} '{url}'".format(
method=method,
headers=" -H ".join(["'{0}: {1}'".format(key, value) for key, value in headers.items()]),
data="" if not data else "--data '{0}'".format(dumps(data)),
Which currently does not consider files at all, but I understand that this a debugging functionality and is not applicable in many other cases.
According to https://github.com/psf/requests/issues/1997 when using files in requests, one is not supposed to provide headers, so that the library will take care of the
multipart/form-data
with the appropriate content-type.An example: (we wrote a custom extension just to do the XRAY API import)
Will result in:
requests.exceptions.HTTPError: 415 Client Error: for url: https://[REDACTED]/rest/raven/1.0/api/import/execution/robot?projectKey=TCHCSIPDEV
This is due to the implementation in
rest_client.py
:If we change this to:
Then the request will work, as the
multipart/form-data
is appropriately handled by the requests library.This is necessary in APIs like XRAY, where one can import result files, which are not JSON. But it should also be applicable for JSON files.