How can I get a Python download image function to work with a local file? For example file:// instead of https://

Viewed 14

I have a Python function 'download_image' which downloads an image from a URI, but I would like to have the function work with a local file on my laptop.

The function is:

def download_image(url):
    resp = requests.get(url)
    resp.raise_for_status()
    return PIL.Image.open(io.BytesIO(resp.content))

This works:

x = download_image('https://assets.bwbx.io/images/users/iqjWHBFdfxIU/iKIWgaiJUtss/v2/1000x-1.jpg')

This does not:

x = download_image('file:///Users/bruceseymour/Coding/images/PrintYumDotCom.jpg')

So I'm trying to use 'file://' instead of 'https://' but I fail.

The error is InvalidSchema: No connection adapters were found for 'file:///User

0 Answers
Related