Using Python PIL to parse .png uploaded to fieldType: "file" property

Hey,

I’m trying to automate the creation of a “branding” object in Django, which includes parsing a .png uploaded to Hubspot through a Form-Submission.

This is what I have right now:

import requests

from PIL import Image

def hs_parse_img(url):

image = Image.open(requests.get(url, stream=True).raw)

return image

hs_parse_img(

"https://api-na1.hubspot.com/form-integrations/v1/uploaded-files/signed-url-redirect/......"

)

When I try to run the script I get the following error:
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at …>
Is it even possible to utilize fieldType: “file” properties in this way?
Thanks

Finally fixed this, after being in contact with HS Support.
The Problem was that my Private App didn’t have the correct Scope (forms-uploaded-files) / that I didn’t pass the headers argument.
This works for me:

HUBAPI_TOKEN = “Bearer INSERT PAT TOKEN HERE”

url_1 = “https://api-na1.hubspot.com/form-integrations/v1/uploaded-files/signed-url-redirect/…”

def hs_get_file(url, headers​:disappointed_face:

auth = {"Authorization": headers}

response = requests.get(url, headers=auth)

return response

print(hs_get_file(url_1, HUBAPI_TOKEN))