selik / xport

Python reader and writer for SAS XPORT data transport files.
MIT License
49 stars 24 forks source link

'ascii' codec can't decode byte 0xd1 #101

Closed lixuezhi001 closed 1 year ago

lixuezhi001 commented 1 year ago

when i open xpt files ,The program occur this problem

label=tokens[5].strip(b'\x00').decode(TEXT_METADATA_ENCODING).rstrip(), UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 0: ordinal not in range(128) i use python3.9.0 please help me,thanks!

caov2021 commented 1 year ago

It should be a encoding issue because this package use default encodings to extract the character . image

You can try the code below and set the encoding which your data used

import xport.v56
from xport.v56 import _encoding

with _encoding(data="utf-8", metadata="utf-8"):
    with open('adae.xpt', 'rb') as f:
        library = xport.v56.load(f)
selik commented 1 year ago

@caov2021 Thanks for helping!

selik commented 1 year ago

Answered.