Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python2.7.12 ProgrammingError err, str(err) occur an error UnicodeEncodeError: 'ascii' codec can't encode character #111

Open
bloodwolf2020 opened this issue Dec 18, 2019 · 0 comments

Comments

@bloodwolf2020
Copy link

i use this in twisted, when sql contain chinese, i exec sql like this:
"select * from test where name = '\xe4\xbd\xa0\xe5\xa5\xbd'"
when table test don't have column [name], an error occur:
ProgrammingError(u'column "name" does not exist\nLINE 1: select * from test where name = '\u4f60\u597d'\n
but in twisted:
def safe_str(o):
"""
Returns a string representation of an object, or a string containing a
traceback, if that object's str raised an exception.

@param o: Any object.

@rtype: C{str}
"""
if _PY3 and isinstance(o, bytes):
    # If o is bytes and seems to holds a utf-8 encoded string,
    # convert it to str.
    try:
        return o.decode('utf-8')
    except:
        pass
try:
    return str(o)
except:
    return _safeFormat(str, o)

last error is 

图片

i must check error.message when an error occur, so i have change code like this:
图片

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant