0

I am trying to call a post request to upload a file to Archer. Please find my code below :

    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
    data = open('testdoc.txt','rb').read()

    url = "http://rsaarcher/platformapi/core/content/attachment" #my archer url

    token = "<my session id token>"
    headers = {
       'Accept':'application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
       'Authorization': 'Archer session-id="'+token+'"',
       'content-type': "application/json;",
       'cache-control': "no-cache",
    }
   response = requests.request("POST", url, data=data, headers=headers, verify = False)

   print(response.content)
   print(response.status_code)

I am getting the following error : b'{"Message":"The request contains an entity body but no Content-Type header. The inferred media type \'application/octet-stream\' is not supported for this resource.","ExceptionMessage":"No MediaTypeFormatter is available to read an object of type \'AttachmentWrapper\' from content with media type \'application/octet-stream\'.","ExceptionType":"System.Net.Http.UnsupportedMediaTypeException","StackTrace":" at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\\r\\n at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)"}' Status code : 415

Nakshatra
  • 11
  • 3

2 Answers2

0

Nakshatra, did you convert the file you're uploading to base64 beforehand?

DjP
  • 308
  • 1
  • 6
  • Yes @DjP, I have used below code for this , but its giving me the same error only : [ with open("1.png", "rb") as img_file: data = base64.b64encode(img_file.read()) ] – Nakshatra Jan 29 '20 at 05:32
0

Ahh, I realized the data you're sending is the incorrect formatted. It should be as follows:

{
    "AttachmentName" : "myFile.docx",
    "AttachmentBytes" : "[base64 here]"
}
DjP
  • 308
  • 1
  • 6