0

I am using an API that returns application/octet-stream. I want to be able to get the content.

Here is what I see in the data section while debugging

    HTTPHeaderDict({'Cache-Control': 'no-cache', 'Pragma': 'no-cache', 'Content-Length': '20738', 
    'Content-Type': 'application/octet-stream', 'Expires': '-1', 'Server': '', 
    'Content-Disposition': 'attachment; filename=Document.pdf', 'X-Powered-By': '', 
    'Date': 'Thu, 09 Mar 2023 22:42:28 GMT'})

Here is the code I am using get this content

    response_returned = https.request(method='POST', url=f'{Checker}/Id/Document/', headers=headers, body=body) 

    response_returned.data does not work.

How can I get this content in python ?

khelwood
  • 55,782
  • 14
  • 81
  • 108
Baba
  • 2,059
  • 8
  • 48
  • 81
  • I have been looking here but no luck. https://urllib3.readthedocs.io/en/stable/reference/urllib3.response.html – Baba Mar 09 '23 at 23:12
  • If the API returns the response as `application/octet-stream`, it means that the content is a binary file, and you need to handle it as binary data in your code. To access binary data of response, I usually use `content` attribute instead of `data`. You can save this (`response_returned.content`) into a file and see if that works. – Nick Mar 10 '23 at 01:04
  • When you say save to a file what does that mean? I am building an API and need to return only the data to the client side. The client side will create the file right? – Baba Mar 10 '23 at 02:10
  • I tried using content now and this is what I got. – Baba Mar 10 '23 at 02:16
  • AttributeError: 'HTTPResponse' object has no attribute 'content' – Baba Mar 10 '23 at 02:16
  • Try `requests` https://stackoverflow.com/questions/14365027/python-post-binary-data – Сергей Кох Mar 10 '23 at 08:12

0 Answers0