Skip to content

io.BytesIO 'file' (such as with twisted or pytest in py2) -> TypeError: 'unicode' does not have the buffer interface #589

@altendky

Description

@altendky

The originating issue occurred while using tqdm in twisted-run tests in py2 (or pytest). You end up with an io.BytesIO as the file which is unable to have a (not-encoded) unicode written to it.

import io
import sys

import tqdm

print(tqdm.__version__, sys.version, sys.platform)

x = [1, 2, 3]

f = io.BytesIO()

for y in tqdm.tqdm(x, file=f):
    pass

https://repl.it/@altendky/SnarlingRuralCustomization

('4.24.0', '2.7.15 (default, Jul 25 2018, 18:24:03) \n[GCC 6.3.0 20170516]', 'linux2')
Traceback (most recent call last):
  File "python", line 12, in <module>
TypeError: 'unicode' does not have the buffer interface

I like to document issues first, but I'll go take a look and see if I can straighten out why tqdm is trying to write unicode to an io.BytesIO that needs bytes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions