简体   繁体   中英

How to convert bytes to string in python

I get the content from webpage like this

url = 'http://s0.icaipiao123.com/api/v2/rank/landing?lottery_key=shuangseqiu'
scode = requests.get(url).content

print(scode.decode('utf8'))

print(type(scode))

print(scode.decode())

The error is 'utf-8' codec can't decode byte 0xeb in position 5: invalid continuation byte

在此处输入图像描述 How to convert bytes to string,thank you

Try this:

import codecs  
#scode data variable
codecs.decode(scode, 'UTF-8') 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM