This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: TypeError: string argument expected, got 'str'
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: amaury.forgeotdarc, dstanek, ezio.melotti, flox, pitrou
Priority: normal Keywords:

Created on 2010-02-26 16:11 by flox, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg100156 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-02-26 16:11
>>> import io; fake = io.StringIO(); fake.write('boo')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: string argument expected, got 'str'
msg100158 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-02-26 16:19
The problem is in Modules/_io/stringio.c, in stringio_write. The error message still uses the py3k wording where 'string' means unicode string. The error should say "unicode argument expected, got 'str'".
There might be similar mistakes around.
msg100159 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-02-26 16:23
The error is slightly different with _pyio:

>>> import _pyio as io; fake = io.StringIO(); fake.write('boo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "./py2trunk/Lib/_pyio.py", line 1559, in write
    s.__class__.__name__)
TypeError: can't write str to text stream

Is it better?
msg100162 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-02-26 16:35
I think the first one is better because it says what it got and what it expects (even if now it's using the wrong word).
msg100166 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-02-26 16:37
> TypeError: can't write str to text stream
>
> Is it better?

There is the same ambiguity in http://docs.python.org/library/io.html
"text" is not defined. And "string" is often used incorrectly.
msg147322 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-11-08 23:52
This was fixed in #12434.
History
Date User Action Args
2022-04-11 14:56:58adminsetgithub: 52273
2011-11-08 23:52:13ezio.melottisetstatus: open -> closed
messages: + msg147322

assignee: ezio.melotti
resolution: duplicate
stage: needs patch -> resolved
2011-01-26 17:52:50dstaneksetnosy: + dstanek
2010-02-26 16:37:15amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg100166
2010-02-26 16:35:47ezio.melottisetmessages: + msg100162
2010-02-26 16:23:35floxsetmessages: + msg100159
2010-02-26 16:19:26ezio.melottisetnosy: + ezio.melotti
messages: + msg100158
2010-02-26 16:11:55floxcreate