You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Misleading IOError when passing a urlopen object in to fits.open() #4165
As noted in the answers, one can already pass a URL as a string in to fits.open() and that will work fine. A urlopen object has never been supported (intentionally) in the first place. But it could be supported easily so long as the file is opened in readonly (or denywrite) mode. It just needs to be handled explicitly. In any case the error message one gets is also misleading:
ERROR: IOError: File-like object does not have a 'write' method, required for mode 'ostream'. [astropy.io.fits.file]
This happens despite not explicitly requesting 'ostream' mode.
@AMAN3003 On GitHub, issues / pull requests that are related to each other show up as cross-references when one references the other. For example, just above your comment you should be able to see two pull requests that reference this issue. One of this PRs is already merged, and references this issue in passing. The other, you can see, is already an attempt to work on this issue (which still needs some work, but it's getting there).
Relatedly, we need to do better at setting the "assignee" to an issue that someone is working on. I think part of this is a UI problem though--GitHub doesn't allow setting an assignee to someone who isn't watching the project.
It appears that this actually already works as expected, at least for the latest version of astropy:
importurllib.requestfromastropy.ioimportfitswithurllib.request.urlopen('file:///path/to/file/that/exists.fits') asurlobj:
withfits.open(urlobj) asfits_handle:
# go to town ...
I added a new unit test demonstrating as much in PR #6378, so hopefully this resolves the issue.
Activity
SanketDG commentedon Sep 20, 2015
Do you mean a
Requestobject?So something like:
embray commentedon Sep 21, 2015
@SanketDG Probably, though this needs to work on Python 2 as well, so also whatever's returned by
urllib2.urlopenwhich I think is something else.Really anything with a
read()method but nowrite()method.lingxz commentedon Oct 14, 2015
@embray would it be better to explicitly check for the urlopen object in
fitsopen()or in
_File()?embray commentedon Oct 15, 2015
All the actual I/O details are handled in the
_Fileclass.fitsopenis purely a UI.AMAN3003 commentedon Jan 25, 2016
@embray is this issue solved if not can i work on this issue
embray commentedon Jan 25, 2016
@AMAN3003 On GitHub, issues / pull requests that are related to each other show up as cross-references when one references the other. For example, just above your comment you should be able to see two pull requests that reference this issue. One of this PRs is already merged, and references this issue in passing. The other, you can see, is already an attempt to work on this issue (which still needs some work, but it's getting there).
Relatedly, we need to do better at setting the "assignee" to an issue that someone is working on. I think part of this is a UI problem though--GitHub doesn't allow setting an assignee to someone who isn't watching the project.
drdavella commentedon Jul 19, 2017
It appears that this actually already works as expected, at least for the latest version of
astropy:I added a new unit test demonstrating as much in PR #6378, so hopefully this resolves the issue.
pllim commentedon Jul 19, 2017
Nothing quite feels so good as a bug that resolved itself. 😂
bsipocz commentedon Jul 20, 2017
@pllim - I'm sure there are still a few hiding in the crowd of the 664 open issues that are solved themselves 😉