Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么SQLAlchemy使用charset=utf8返回python类型创建_引擎<;str>;而不是类型<;unicode>;?_Python_Mysql_Unicode_Utf 8_Sqlalchemy - Fatal编程技术网

为什么SQLAlchemy使用charset=utf8返回python类型创建_引擎<;str>;而不是类型<;unicode>;?

为什么SQLAlchemy使用charset=utf8返回python类型创建_引擎<;str>;而不是类型<;unicode>;?,python,mysql,unicode,utf-8,sqlalchemy,Python,Mysql,Unicode,Utf 8,Sqlalchemy,使用Python 2.7和SQLAlchemy 0.7,我使用以下命令连接到MySQL数据库: engine = create_engine('mysql://username:password@host/dbname?charset=utf8',echo=False) 根据SQLAlchemy文档,设置charset=utf8自动意味着使用\u unicode=1,因此所有字符串都应返回为unicode。具体举例说明 #将客户端编码设置为utf8;所有字符串返回为unicode 创建搜索引擎

使用Python 2.7和SQLAlchemy 0.7,我使用以下命令连接到MySQL数据库:

engine = create_engine('mysql://username:password@host/dbname?charset=utf8',echo=False)
根据SQLAlchemy文档,设置charset=utf8自动意味着使用\u unicode=1,因此所有字符串都应返回为unicode。具体举例说明

#将客户端编码设置为utf8;所有字符串返回为unicode 创建搜索引擎('mysql+mysqldb:///mydb?charset=utf8")

那么,为什么在查询映射类中的文本字段时,该字段的结尾是“str”类型呢

输出是

 <type 'str'>


如果我接受这一点并在使用它之前对字符串进行解码,一切都很好。但是我不明白为什么上面的代码没有返回类型“unicode”。有人能解释一下吗?

当我发现我多次成功运行的另一个脚本不再工作时,终于找到了答案

我已将数据库中的排序规则从utf8\u general\u ci更改为utf8\u bin。MySQLDB1.2.3中存在一个错误,导致utf8_bin字符串无法识别为文本,因此无法进行unicode转换。这在MySQLDB1.2.4中已修复


从您的
打印页面上的选项看,您似乎正在使用Python 3.x。是这样吗?哦,不,对不起,我应该指定我正在使用Python2.7和SQLAlchemy版本0.7。我做了一个“从未来导入打印功能”。
 <type 'str'>