我使用 Python Requests 发送 HTTP 请求,作为回报,我将从服务器获取 PNG 流。
r = self.a.send_request()
self.assertEqual(
'png',
imghdr.what(None, r),
"Couldn't get a PNG ImageGraph"
)
此代码导致:
imghdr TypeError:startswith first arg must be str
imghdr.what(filename[, h])
Tests the image data contained in the file named by filename, and returns a string describing the image type. If optional h is provided, the filename is ignored and h is assumed to contain the byte stream to test.
为什么即使使用字节流我仍然会收到错误消息?
编辑 1:包括来自服务器的 HTTP 响应。