待研究:

compressed_data = zlib.compress(json.dumps(data), 9)
file_data = MySQLdb.escape_string(compressed_data)
sql = "INSERT INTO declare_unit_inner_data " \
              "(d_id, w_id, a_id,file_data,`type`) " \
              "values (%s, %s, %s, '%s', %s) " \
              % (d_id, w_id, a_id,
                 file_data, type_flag)

上面的sql,file_data 是经过zlib压缩的json字符串,在拼接sql时,始终报错误: UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position 1: ordinal not in range(128)

当使用int(w_id)把w_id转换成整形后,问题解决,初始的w_id是字符串,不理解原因。

posted on 2018-02-09 16:45  Go_Forward  阅读(328)  评论(0编辑  收藏  举报