imghdr fail to run from http stream

193 Views Asked by At

I use Python Requests to send a HTTP request, and in return I will get a stream of PNG from the server.

    r = self.a.send_request()
    self.assertEqual(
        'png',
        imghdr.what(None, r),
        "Couldn't get a PNG ImageGraph"
    )

This code results in:

imghdr TypeError: startswith first arg must be str

According to Python documentation,

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.

Why do I still get the error even with byte stream?


Edit 1: Include the HTTP response from server.

Screenshot of Chrome Developer tools from server PNG response

0

There are 0 best solutions below