Error message generated when you pass fits.open bytes instead of string-like is confusing.
See original GitHub issueI unintentionally passed fits.open a bytes object instead of str-like object the error that is generated doesn’t really indicated if it is unsupported? If it is supposed to be supported then I’ve found a bug. Code below shows minimal example of how to reproduce if you have a fits file handy.
pathtofits = "<path to a fits file>"
hdus = fits.open(pathtofits) #Works perfectly
hdus = fits.open(pathtofits.encode()) #Crash
<large stack trace>
OSError: File-like object does not have a 'write' method, required for mode 'ostream'.
OS: macOS 10.12.6 Python: 3.6.2 Astropy: 2.0.2
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
FITS File Handling (astropy.io.fits)
The open function returns an object called an HDUList which is a list -like collection of HDU objects. An HDU (Header Data Unit)...
Read more >What's the correct way to convert bytes to a hex string in ...
I see claims of a bytes.hex method, bytes.decode codecs, and have tried other possible functions of least astonishment without avail. I just want...
Read more >4. Text versus Bytes - Fluent Python [Book] - O'Reilly
Implicit conversion of byte sequences to Unicode text is a thing of the past. This chapter deals with Unicode strings, binary sequences, and...
Read more >astropy.io.fits FAQ
Astropy crashed and output a long string of code. What do I do? Why does opening a file work in CFITSIO, ds9, etc....
Read more >Language Guide | Protocol Buffers - Google Developers
For Go, the compiler generates a .pb.go file with a type for each message type in your file. You can find out more...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It works if one also changes
https://github.com/astropy/astropy/blob/v2.0.2/astropy/io/fits/util.py#L419-L420
to accept
bytes
.@samaloney yes
TestFileFunctions
would be a good place to add this test. It would also be useful to add awriteto
test as well.