api response shows some black rectangles and question marks inside it

Question:

I have been using openKM for document management and after retrieving image from openkm using api it shows question marks rectangles.

I have already checked this question but did not help
.

my python code for making api request

any help will be much appreciated

url = "http://ipaddress/aa18be7a5/hhhhhggg.png"

payload={}
headers = {'Internal-Key':"gjffhddsgsgdfgkhkhggdgsfd"}
response = requests.request("GET", url, headers=headers, data=payload)
return response.text

Asked By: Naqib007

||

Answers:

You requested .PNG data, and that’s what the server sent you.
It all looks good.

You did this

response = requests.request("GET", url, ...)
return response.text

The request is beautiful.

But then you looked at .text, hoping for some unicode.
That would make sense, on a text document.
But instead you obtained a binary PNG document.
Just look at the returned headers — they will
explain that its "Content-type" is "image/png".

You want response.content instead,
which is uninterpreted binary bytes,
suitable for writing to some "foo.png" file for display.
(Remember to use "wb" as the open() mode, not just "w"!)

It’s important to understand that some byte strings
do not form valid utf-8, and trying to treat
binary images as unicode will soon end in tears.

Answered By: J_H