简体   繁体   English

api 响应中显示了一些黑色矩形和问号

[英]api response shows some black rectangles and question marks inside it

I have been using openKM for document management and after retrieving image from openkm using api it shows question marks rectangles .我一直在使用 openKM 进行文档管理,在使用 api 从 openkm 检索图像后,它显示问号矩形

I have already checked this question but did not help.我已经检查过这个问题但没有帮助。

my python code for making api request我的 python 代码用于发出 api 请求

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

You requested.PNG data, and that's what the server sent you.你请求.PNG 数据,这就是服务器发送给你的。 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.但随后您查看了.text ,希望得到一些 unicode。在文本文档中,这是有道理的。 But instead you obtained a binary PNG document.但是您获得了一个二进制 PNG 文档。 Just look at the returned headers -- they will explain that its "Content-type" is "image/png".只需查看返回的标头——它们会解释其“内容类型”是“图像/png”。

You want response.content instead, which is uninterpreted binary bytes, suitable for writing to some "foo.png" file for display.您需要response.content ,它是未解释的二进制字节,适合写入某些“foo.png”文件以供显示。 (Remember to use "wb" as the open() mode, not just "w" !) (请记住使用"wb"作为 open() 模式,而不仅仅是"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.重要的是要了解一些字节串不构成有效的 utf-8,并且试图将二进制图像视为 unicode 很快就会以泪流满面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM