[New-bugs-announce] [issue10863] zlib.compress() fails with string

Jose-Luis Fernandez-Barros report at bugs.python.org
Fri Jan 7 21:02:51 CET 2011

New submission from Jose-Luis Fernandez-Barros <jlfbarros at gmail.com>:

On "The Python Tutorial", section 10.9. Data Compression

>>> import zlib
>>> s = 'witch which has which witches wrist watch'
>>> t = zlib.compress(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must be bytes or buffer, not str

Possible solution (sorry, newbie) are:
>>> s = b'witch which has which witches wrist watch'
>>> s = 'witch which has which witches wrist watch'.encode("utf-8")

At "The Python Standard Library", secction 12. Data Compression and Archiving
apparently example is correct:
  zlib.compress(string[, level])

assignee: docs at python
components: Documentation
messages: 125702
nosy: docs at python, joseluisfb
priority: normal
severity: normal
status: open
title: zlib.compress() fails with string
type: compile error
versions: Python 3.1

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list