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: UnicodeEncodeError: 'ascii' codec can't encode character
Type: Stage:
Components: Unicode Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Muallim-i Âli, georg.brandl
Priority: normal Keywords:

Created on 2008-05-29 07:58 by Muallim-i Âli, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
site.py Muallim-i Âli, 2008-05-29 07:58 python module
Messages (3)
msg67478 - (view) Author: Rahman (Muallim-i Âli) Date: 2008-05-29 07:58
Hi i Rahman Yazgan. I live in Turkey. I am pyhton(pyqt) programmer.

I found a bug :

UnicodeEncodeError: 'ascii' codec can't encode character

QLineEdit.text(),... UnicodeEncodeError so ascii codecs, can't encoding.

python version 2.5(windows)  python25/lib/site.py line 381-383 :

    if encoding != "ascii":
        # On Non-Unicode builds this will raise an AttributeError...
        sys.setdefaultencoding(encoding) # Needs Python Unicode build !

UnicodeEncodeError: 'ascii' codec can't encode character so resoluble:

    if encoding != "ascii":
        # On Non-Unicode builds this will raise an AttributeError...
        sys.setdefaultencoding(encoding) # Needs Python Unicode build !

    if encoding == "ascii":
        sys.setdefaultencoding("utf-8")
msg67494 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-05-29 14:34
Sorry, but you have to be more specific about what you think is a bug.
That the default encoding is ascii does have its reasons, and will not
change.

You're likely to be missing an explicit .encode() call when converting
from unicode to str; consult a Python mailing list or newsgroup with
details.
msg67519 - (view) Author: Rahman (Muallim-i Âli) Date: 2008-05-30 06:03
Thank you.

Turkish characters no problem : 

unicode(self.ui.lineEdit.text()).encode(utf-8)
History
Date User Action Args
2022-04-11 14:56:35adminsetgithub: 47248
2008-05-30 06:03:07Muallim-i Âlisetmessages: + msg67519
2008-05-29 14:34:50georg.brandlsetstatus: open -> closed
resolution: not a bug
messages: + msg67494
nosy: + georg.brandl
2008-05-29 07:58:43Muallim-i Âlicreate