Author mdehoon
Recipients mdehoon
Date 2012-12-19.06:42:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1355899334.66.0.683261774989.issue16723@psf.upfronthosting.co.za>
In-reply-to
Content
I am trying to use io.TextIOWrapper to wrap a handle returned by urllib.request.urlopen. Reading line-by-line from the wrapped handle terminates prematurely.

As an example, consider this script:

import urllib.request
import io

url = "http://www.python.org"
handle = urllib.request.urlopen(url)
wrapped_handle = io.TextIOWrapper(handle, encoding='utf-8')
for line in wrapped_handle:
    pass

This gives:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: I/O operation on closed file.

This happens after 335 out of the 430 lines have been read (the last line read is "<p>The <a class="reference external" href="/psf/">Python Software Foundation</a> holds the intellectual property\n", which is line 335 on the www.python.org website.
History
Date User Action Args
2012-12-19 06:42:14mdehoonsetrecipients: + mdehoon
2012-12-19 06:42:14mdehoonsetmessageid: <1355899334.66.0.683261774989.issue16723@psf.upfronthosting.co.za>
2012-12-19 06:42:14mdehoonlinkissue16723 messages
2012-12-19 06:42:12mdehooncreate