Hey guys, simple question. How do I download a png image into an object from a url?
I tried using the anvil built in HTTP methods, but I’m getting a strange error…
Here’s the method I constructed and called with a hardcoded url for testing purposes:
def button_tree_click(self, **event_args):
"""This method is called when the button is clicked"""
anvil.http.request('https://api.deepai.org/job-view-file/bc5bbb1c-7cbb-4f9a-a819-d448768b7816/outputs/output.png')
I’m getting an error message of
UnicodeDecodeError: invalid string at index 0 (possibly contains a unicode character)
I know the url is good, as I can download the picture manually by using my browser. I tried looking in the anvil docs and fourms to see if anybody had any similar issues. Thanks in advance.
Edit:
I was able to get some sort of result text for a png image by using the following methodology, but I’m not sure how to stuff it into a media object I can download. Here’s the method:
@anvil.server.callable
def png_request():
r = requests.get('https://api.deepai.org/job-view-file/7ebf2d7d-a5b5-408f-a1a2-641b8234bd8a/outputs/output.png')
c = r.content
print(c)