question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow custom urlopen for astropy.utils.data.download_file

See original GitHub issue

The astropy.utils.data module is excellent, but restricted to ‘simple’ downloads. so I’m wondering if there is scope for a change such that users could use functions other that urlopen in download_file()?

My specific use case is for accessing files from behind an authentication layer, where we have a wrapper around urlopen that handles authentication redirects and all that.

Something like this would be great:

def download_file(remote_url, cache=False, show_progress=True,
                  opener=urllib.request.urlopen, **kwargs):

where kwargs then get passed to the opener. If the powers-that-be are open to the idea, I’m happy to work up a prototype and post a PR.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
duncanmmacleodcommented, May 1, 2018

I now wonder whether this might be possible just using mock:

with mock.patch('urllib.request.urlopen', side_effect=mycustomopener):
    download_file(...)

Since I seem to be the only requester of this functionality I think we can close this issue now, and I can post a PR with a proper implementation of my initial suggestion if required.

0reactions
eteqcommented, Dec 13, 2017

My position has generally been that download_data and get*file* are considered “public” because of just the reason @duncanmmacleod gave - that it’s already there and useful so why not let people use it.

That said, I am sensitive to the point that it’s “feature creep” to keep adding options to maintain. E.g., we’d rather the progress bar get replaced by tqdm instead of maintaining our own (been on the todo list for a while). But I think I’m receptive to the idea @duncanmmacleod is suggesting here of basically making it more able to use other functions, because that might actually encourage use of other tools. But as @pllim says, devil is in the details, so would need to see a PR or at least a bit more detail to be entirely sure how much maintenance burden is likely…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Downloadable Data Management (astropy.utils.data)
In this case, you may pass the allow_insecure=True argument to download_file() to allow the download with a warning instead (not recommended unless you ......
Read more >
How do I open a FITS file from a URL in astropy?
If the file name is a URL, download_file is used to open the file. This specifies whether or not to save the file...
Read more >
Source code for astropy.utils.data
If args[1] is present, it is a filename indicating the path to a temporary file that was created to store a remote data...
Read more >
astroquery Documentation
All astroquery modules are supposed to follow the same API. In its simplest form, the API involves queries based on.
Read more >
astropy/data.py at main - GitHub
Returns the local path that the file was download to. Raises. ------. urllib.error ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found