Ascii UnicodeEncodeError with raw sql query via execute() using SQLAlchemy + mysql-connector-python and Python 3.4 -
given following (run interactive shell):
from sqlalchemy import create_engine sqlalchemy.orm import scoped_session e = create_engine("mysql+mysqlconnector://{dbuser}:{dbpass}@{dbhost}/{schema}", encoding="utf8") row in e.execute("select * some_table t join some_join j on t.link_id = j.link_id"): print(dict(row))
i'm receiving following error:
traceback (most recent call last): file "<stdin>", line 2, in <module> unicodeencodeerror: 'ascii' codec can't encode character '\xe1' in position 195: ordinal not in range(128)
the database content has lot of non-ascii characters in text fields , tables 'utf8_general_ci' collated.
i've tried multiple combinations of connection string/create_engine parameters (use_unicode, encoding etc.) , far nothing has affected outcome.
by would've cheated , iterated on attributes on 'row' , encoded them individually necessary, 'row' instance of rowproxy class doesn't have attributes of (related database columns anyway,) path difficult.
anyway i'd rather not cheat , individually manage encoding/decoding - there global option or initial setup i'm missing allow me handle utf-8 content in python 3.4?
edit: thanks @deets in comments, i've found error caused print(), manipulating data otherwise fine.
Comments
Post a Comment