Message177726
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. |
|
Date |
User |
Action |
Args |
2012-12-19 06:42:14 | mdehoon | set | recipients:
+ mdehoon |
2012-12-19 06:42:14 | mdehoon | set | messageid: <1355899334.66.0.683261774989.issue16723@psf.upfronthosting.co.za> |
2012-12-19 06:42:14 | mdehoon | link | issue16723 messages |
2012-12-19 06:42:12 | mdehoon | create | |
|