S3OpenRead doesn't work with TextIOWrapper
See original GitHub issueCurrently only binary-mode read is supported, which would be OK if the stream you returned worked with TextIOWrapper
– but it doesn’t, at least not S3OpenRead
. TextIOWrapper
expects readable, writable, seekable, closed etc methods. If you make S3OpenRead inherit (or quack like) IOBase
that should fix it.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Problem with TextIOWrapper - doesn't read entire file
I'm trying to read the output file of a simulation and grap some data (elapsed CPU time). I've tried multiple ways of doing...
Read more >io — Core tools for working with streams
This is a helper function for callables that use open() or TextIOWrapper and have an encoding=None parameter. This function returns encoding if it...
Read more >How to read from a text file
To work with a text file in Python, you can use the built-in open function, ... TextIOWrapper object, but we don't talk about...
Read more >python textiowrapper - You.com | The Search Engine You ...
zipfile.open opens the zipped file in binary mode, which doesn't strip out carriage returns (i.e. '\r'), and neither did the defaults for TextIOWrapper...
Read more >25576 (HttpResponse can't be wrapped by io.TextIOWrapper
TextIOWrapper ; add required IOBase methods ... In Python3, the stdlib CSV writer [1] is expected to write to a text file, not...
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
Hey, sorry I’m unlikely to get around to this as it stands – we’ve worked around it like so, although this won’t work for everyone:
To be honest smart_open feels like quite a leaky abstraction due to patchy / partial support for various features, meaning you need extra special-cased dispatch and wrapping code after parsing the URL yourself. E.g. gzip only working for local files, some other common compression formats not supported, text mode not working for S3, https issues. Maybe some of those are fixed now, but if I was to revisit I’d be tempted to just manually wrap the streams from the underlying libraries myself.
If you wanted to address that in a deeper way, I’d suggest making sure any stream implementations here respect the stream interfaces from the standard library ( https://docs.python.org/3/library/io.html ), which would make it easier to write general and composable code that builds on them. Perhaps some of that would be easier if you give up on Python 2. Then try and implement features like compression and text mode support in a general way where possible via wrapping streams, and make the dispatch mechanisms (for protocols, compression formats etc) extensible.
great @mpenkov, fixed by #131