Skip to content

Save result locally #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nomeata opened this issue Oct 6, 2022 · 3 comments
Closed

Save result locally #48

nomeata opened this issue Oct 6, 2022 · 3 comments

Comments

@nomeata
Copy link

nomeata commented Oct 6, 2022

The predict function call returns the resulting images as URL, and if I want to store them locally, I still have to fetch that. But a simple

urllib.request.urlretrieve(output[0], filename)

will fail with 403 because of lack of authentication; I have to include the authentication header in that request.

It would be convenient if the replicate library would assist with that, so that the user does not have to know how to include the token in the request.

@nomeata
Copy link
Author

nomeata commented Oct 6, 2022

Just in case anyone hits the same issue: This is the code I’m using now:

opener = urllib.request.build_opener()
opener.addheaders = [('Authentication', 'Token ' + os.environ.get("REPLICATE_API_TOKEN"))]
urllib.request.install_opener(opener)
urllib.request.urlretrieve(output[0], filename)

@TTCooper-PhD
Copy link

Just in case anyone hits the same issue: This is the code I’m using now:

opener = urllib.request.build_opener()
opener.addheaders = [('Authentication', 'Token ' + os.environ.get("REPLICATE_API_TOKEN"))]
urllib.request.install_opener(opener)
urllib.request.urlretrieve(output[0], filename)

Thank you!

@bfirsh
Copy link
Member

bfirsh commented Jan 30, 2023

This is now fixed by having a short-lived hard-to-guess URL.

@bfirsh bfirsh closed this as completed Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants