New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
urllib.request.urlopen does not return an iterable object #48858
Comments
$ cat urltest2.5
#!/usr/bin/python2.5
from urllib2 import urlopen
for line in urlopen('http://python.org/'):
print line
break
$ ./urltest2.5
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
$ cat urltest3.0
#!/usr/bin/python3.0
from urllib.request import urlopen
for line in urlopen('http://python.org/'):
print(line)
break $ ./urltest3.0
Traceback (most recent call last):
File "./urltest3.0", line 3, in <module>
for line in urlopen('http://python.org/'):
TypeError: 'addinfourl' object is not iterable |
I verified this bug in the Py3.0 and Py3.1. Shall come out with a patch |
Oops. I didn't think it translate the code in addinfobase to the new Jeremy On Tue, Dec 9, 2008 at 7:50 AM, Senthil <report@bugs.python.org> wrote:
|
Here is a patch to fix the issue. |
Regarding Senthil's patch: |
Jakub, I have attached a revision to the patch. This is implemented in the similar lines of IOBase class, io.py Thanks, |
Oops, __next__ is OK. Sorry for the confusion. |
Senthil, do you think you could provide a test case for this? Thank you! |
Test cases attached. The second one highlights a bug in the current patch, as it fails to |
This issue is already fixed by jeremy at Revision 70815, wherein "The So the issue won't be present in the py3k code ( confirmed). However, the test added by Daniel,which tests for urlopen() for a It is not just with iteration; but test_200 will fail too if the request |
This looks as though its a short write: [pid 28343] recvfrom(5, "GET / HTTP/1.1\r\nAccept-Encoding:"..., 8192, 0, NULL, NULL) = 118 |
The attached patch handles short writes, and adds ajaksu2's tests. |
Thanks, Brian. |
This issue appears to persist when the protocol used is FTP: root@tp-db $ cat test.py root@tp-db $ python3.2 test.py
Traceback (most recent call last):
File "test.py", line 2, in <module>
for line in urlopen('ftp://gentoo.osuosl.org/pub/gentoo/releases/'):
TypeError: 'addinfourl' object is not iterable |
Oops, previous example was a directory, but it's the same if the url points to a ftp file. |
The patch that makes addinfourl() iterable was not commited due to the change to HTTP request see: msg86365 (http://bugs.python.org/issue4608#msg86365). Since urllib is protocol agnostic it should behave the same with FTP, right? So, where to fix? Change the addinfourl() to become itrable or change the FTPHandler return? |
It turned out that although the addinfourl instance had the Riccardo Attilio Galli and I made the attached patch. The patch also fixes a corresponding |
New changeset c0a68b948f5d by Raymond Hettinger in branch '3.2': New changeset d4aeeddf72e3 by Raymond Hettinger in branch 'default': |
Thanks for the patch. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: