#create_variation gives text decode error

3 messages · Page 1 of 1 (latest)

void cape
#

Okay so I might just be stupid, but when I use the following code:

response = openai.Image.create_variation(image = open("source.png"), n = 4)

It gives an error:

'charmap' codec can't decode byte 0x9d in position 87: character maps to <undefined>

I'm assuming this is to do with open() being mainly for text files and not images. But the documentation says image = open(filename) is the correct way to do it. What am I missing here?

#

I also tried having the parameter be just a string, e.g. image = "source.png". If I do that, it says "Uploaded image must be a PNG and less than 4 MB.", despite the fact that the image I'm using is a PNG and it's only 1.51 MB. Still, that might be closer to the right output.

void cape
#

Fixed it; I had to open the image in read-binary mode, e.g. image = open("source.png", "rb")