Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue7399] Possible bug in Python Tutorial

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Nov 26, 2009, 8:30 AM

Post #1 of 2 (222 views)
Permalink
[issue7399] Possible bug in Python Tutorial

New submission from David Henretty <dhenretty [at] a2etech>:

Hi,

In the v3.1.1 Python Tutorial (section 10.7 - Internet Access), the
sample code (shown below) results in the following error :-

from urllib.request import urlopen
for line in urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl'):
if 'EST' in line or 'EDT' in line:
print(line)

Traceback (most recent call last):
File "<stdin>", line 2, in <module>
TypeError: Type str doesn't support the buffer API

I presume this has something to do with the assumed type of the
variable 'line', but I am very new to Python.

Replacing the 'if' line with the following DOES work :-

if 'EST' in str(line) or 'EDT' in str(line):

Can anyone confirm / explain this ?

Thanks,

DH

----------
assignee: georg.brandl
components: Documentation
messages: 95749
nosy: dh, georg.brandl
severity: normal
status: open
title: Possible bug in Python Tutorial
type: compile error
versions: Python 3.1

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7399>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 26, 2009, 10:22 AM

Post #2 of 2 (199 views)
Permalink
[issue7399] Possible bug in Python Tutorial [In reply to]

R. David Murray <rdmurray [at] bitdance> added the comment:

The example is indeed wrong. urlopen is returning an object that emits
binary data. The error comes from using 'in' on incompatible types.
The solution is to encode the data with an appropriate encoding, once
you figure out what that is.

----------
nosy: +r.david.murray
priority: -> normal
stage: -> needs patch
type: compile error -> behavior
versions: +Python 3.2

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7399>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.