Closed giorgos83b closed 3 years ago
I have a special character in my name and I can read my vaccine cert just fine.
I think this is a problem with lack of utf-8 support in Python on Windows. I have no idea what I can do about that. Any proposal?
It's a problem of pprint
Fixed in https://github.com/hannob/vacdec/pull/9
See my fork: https://github.com/HQJaTu/vacdec/tree/signature-verification
There I specifically use Swedish sample data with name of Oscar Lövström to demonstrate problem being solved.
From what I can see this is ultimately an issue with the environment not supporting utf-8. I'll close this for now, if anyone has a proposal how to workaround this in a simple way I'm happy to merge that. However I'm not gonna merge the solution from the linked stackoverflow post as that's excessively complicated and I want to keep this script simple.
Original code:
pprint.pprint(cbor2.loads(decoded.value[2]))
My fork's code handling both vaccinations with time-of-day and UTF-8 characters:
cbor = cbor2.loads(cose_msg.payload)
json.dumps(cbor, indent=2, default=str, ensure_ascii=False)
ensure_ascii
default=str
{-260: {1: {'dob': 'xxxx-xx-xx', 'nam': {'fn': Traceback (most recent call last): File "vacdec.py", line 19, in
pprint.pprint(cbor2.loads(decoded.value[2]))
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 53, in pprint
printer.pprint(object)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 139, in pprint
self._format(object, self._stream, 0, 0, {}, 0)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 167, in _format
p(self, object, stream, indent, allowance, context, level + 1)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 189, in _pprint_dict
context, level)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 346, in _format_dict_items
context, level)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 167, in _format
p(self, object, stream, indent, allowance, context, level + 1)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 189, in _pprint_dict
context, level)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 346, in _format_dict_items
context, level)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 167, in _format
p(self, object, stream, indent, allowance, context, level + 1)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 189, in _pprint_dict
context, level)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 346, in _format_dict_items
context, level)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 167, in _format
p(self, object, stream, indent, allowance, context, level + 1)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 189, in _pprint_dict
context, level)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 346, in _format_dict_items
context, level)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 176, in _format
stream.write(rep)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 1-9: character maps to