pandas.read_sql 的 UnicodeDecodeError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40231498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 02:16:47 来源:igfitidea点击:
UnicodeDecodeError with pandas.read_sql
提问by spiff
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 8: character maps to <undefined>
Am seeing teh above error in a simple sql query:
我在一个简单的 sql 查询中看到上述错误:
df = pd.read_sql(query,connection)
I tried the query normally on sql developer and it works perfectly fine.. really stumped here as to how to specify encoding in a read_sql call
我在 sql developer 上正常地尝试了查询,它工作得很好。
Am using Python 3.4 and pandas version 0.14.1
我正在使用 Python 3.4 和 Pandas 版本 0.14.1
Thanks very much!
非常感谢!
回答by Hisham Karam
回答by Vlad
Python3.7:
Python3.7:
con = sqlite3.connect(path_to_db)
encoding = "latin1"
con.text_factory = lambda x: str(x, encoding)
# do not preserve non-printable
# con.text_factory = lambda x: str(x, "ascii", errors="ignore")
data = pd.read_sql_query(QUERY, con)