[New-bugs-announce] [issue16723] io.TextIOWrapper on urllib.request.urlopen terminates prematurely

Michiel de Hoon report at bugs.python.org
Wed Dec 19 07:42:14 CET 2012


New submission from Michiel de Hoon:

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.

----------
messages: 177726
nosy: mdehoon
priority: normal
severity: normal
status: open
title: io.TextIOWrapper on urllib.request.urlopen terminates prematurely
type: behavior
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16723>
_______________________________________


More information about the New-bugs-announce mailing list