python 报错TypeError: can only concatenate str (not "bytes") to str

背景:项目Python2.7升级到Python3.8,Django1.10升级到Django3.0

因为python3.4后不能直接使用unicode(value, 'utf-8')了

所以代码

data = '{"id":"' + location_key_id + '","location_name": "' + unicode(location_name, 'utf-8') + '","leaf:"'+true+'"}'

需要删除,可以直接变成:

data = '{"id":"' + location_key_id + '","location_name": "' + location_name + '","leaf:"'+true+'"}'

但是调用代码是报错

can only concatenate str (not "bytes") to str

修改成:

data = '{"id":"' + location_key_id + '","location_name": "' + str(location_name) + '","leaf:"'+true+'"}'

问题解决!!!

你可能感兴趣的:(python包,django,unicode,Python3.8,Python2.7,Django3.0,Django1.10,unicode)