Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unicode to utf-8
#2
Please post your current code, outputs and errors?
Are you using Python3,right?

Are you getting this error?
Output:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
You can use replace or ignore when decoding:

>>> b'\x80abc'.decode("utf-8", "strict")  
Traceback (most recent call last):
    ...
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0:
  invalid start byte
>>> b'\x80abc'.decode("utf-8", "replace")
'\ufffdabc'
>>> b'\x80abc'.decode("utf-8", "backslashreplace")
'\\x80abc'
>>> b'\x80abc'.decode("utf-8", "ignore")
'abc'
Reply


Messages In This Thread
unicode to utf-8 - by Skaperen - Jul-21-2018, 04:24 AM
RE: unicode to utf-8 - by gontajones - Jul-21-2018, 03:07 PM
RE: unicode to utf-8 - by Skaperen - Jul-21-2018, 08:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  clean unicode string to contain only characters from some unicode blocks gmarcon 2 4,087 Nov-23-2018, 09:17 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020