classification
Title: TextIOWrapper fails with SystemError when reading HTTPResponse
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.0, Python 3.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, jhylton, orsenthil, pitrou
Priority: high Keywords:

Created on 2009-03-31 17:08 by jhylton, last changed 2009-05-14 21:15 by benjamin.peterson. This issue is now closed.

Messages (10)
msg84840 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2009-03-31 17:08
import io
import urllib.request

f_bytes = urllib.request.urlopen("http://www.python.org/")
f_string = io.TextIOWrapper(f_bytes, "iso-8859-1")
print(f_string.read())
msg84945 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-03-31 23:11
Fixed in r70928.
msg84951 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2009-04-01 00:04
Nope, this is not yet fixed.

$ ./python 
Python 3.1a1+ (py3k:70929, Mar 31 2009, 19:18:12) 
[GCC 4.3.2] on linux2
...
...
>>> f_bytes = urllib.request.urlopen("http://www.python.org")
>>> f_string = io.TextIOWrapper(f_bytes,"iso-8859-1")
>>> print(f_string.read())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: not readable
msg84953 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-04-01 00:36
urllib.response.addinfourl doesn't seem to implement the required ABC
(BufferedIOBase) properly. It misses the read1() method. Also, it claims
not to be readable:

>>> f_bytes = urllib.request.urlopen("http://www.python.org/")
>>> f_bytes.readable()
False
msg84961 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2009-04-01 02:26
I just wanted to mention that the current head of py3k returns an
http.client.HTTPResponse and not a urllib.respone.addinfourl.  That
doesn't mean it is the right thing to pass to TextIOWrapper.  It's an
instance of RawIOBase.
msg84963 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2009-04-01 02:34
Jeremy Hylton  wrote:
>  That doesn't mean it is the right thing to pass to TextIOWrapper.  It's an
> instance of RawIOBase.

I guess, you meant " That doesn't mean it is *not* the right thing to
pass to TextIOWrapper".
msg84968 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2009-04-01 03:04
With the changes r70935, this works.
msg84970 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-04-01 03:17
Please note that passing a instance of RawIOBase (as HTTPResponse) is
to TextIOWrapper is *not* supported. You must first wrap the raw IO in
a BufferIOBase instance.
msg87764 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-05-14 21:12
I suppose it is fixed, isn't it?
msg87765 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-05-14 21:15
Yes
History
Date User Action Args
2009-05-14 21:15:12benjamin.petersonsetstatus: pending -> closed
resolution: fixed
messages: + msg87765
2009-05-14 21:12:27pitrousetstatus: open -> pending

messages: + msg87764
2009-04-01 03:17:05benjamin.petersonsetmessages: + msg84970
2009-04-01 03:04:29orsenthilsetmessages: + msg84968
2009-04-01 02:34:31orsenthilsetmessages: + msg84963
2009-04-01 02:26:47jhyltonsetmessages: + msg84961
2009-04-01 00:38:17pitrousetpriority: high
type: behavior
resolution: accepted -> (no value)
versions: + Python 3.1
2009-04-01 00:36:06pitrousetnosy: + pitrou
messages: + msg84953
2009-04-01 00:04:28orsenthilsetstatus: closed -> open

nosy: + orsenthil
messages: + msg84951

resolution: fixed -> accepted
2009-03-31 23:11:55benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg84945

resolution: fixed
2009-03-31 17:08:43jhyltoncreate