python UnicodeDecodeError

#encoding=utf-8
current_event='\xe5\xb7\xb2\xe7\xad\xbe\xe6\x94\xb6,\xe7\xad\xbe\xe6\x94\xb6\xe4\xba\xba\xe6\x98\xaf \xe6\x8b\x8d\xe7\x85\xa7\xe7\xad\xbe\xe6\x94\xb6\xa0\xa0\xe6\x9f\xa5\xe7\x9c\x8b\xe7\xad\xbe\xe6\x94\xb6\xe5\x9b\xbe\xe7\x89\x87' 
current_event = unicode(current_event,'utf-8',errors='replace').encode('utf-8')
#current_event = current_event.decode('utf-8','ignore').encode('utf-8')
print current_event

current_event中含有乱码\xa0\xa0

已签收,签收人是 拍照签收��查看签收图片

存入数据库时会报错

UnicodeDecodeError: 'utf8' codec can't decode byte 0xa0 in position 35: invalid start byte

忽略乱码可以用

unicode(current_event,'utf-8',errors='replace').encode('utf-8')

或者

current_event = current_event.decode('utf-8','ignore').encode('utf-8')

你可能感兴趣的:(python)