'Python crashing while opening a image

I am getting an image using an API call and eventually need to put the image into a PDF document using ReportLab. Python was crashing without any error messages when I tried canvas.drawImage method in ReportLab. In order to isolate the issue, I just tried opening the image using the Image class and Python still crashes. I can open the image manually using paint and the code does not error out when using other images, leading me to believe I am missing something while converting the binary to the image. I cannot share the images or the API. The definition of the result from the API is as follows.

<GetImageResponse xmlns="http://tempuri.org/">
  <GetImageResult>base64Binary</GetImageResult>
  <errorMessages>string</errorMessages>
</GetImageResponse>

'''

from zeep import Client
import base64

from PIL import Image, ImageTk 
client=Client(wsdl='******.asmx?wsdl')
imgService=client.service.GetImage("***",****, "***********")
imgFile="imageTest.png"
base64_bytes = base64.b64encode(imgService.GetImageResult)
with open(imgFile, "wb") as fh:
    fh.write(base64.decodebytes(base64_bytes))  
image = Image.open(imgFile)
image.show()

'''

Can someone point me where I need to look? Thanks in advance for any pointers.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source