Skip to content

Conversation

@smihael
Copy link

@smihael smihael commented Feb 3, 2022

Python 3 handles strings with two different types.

sys.stdout.write(data)

expects type(data) to be <class 'str'> and not <class 'bytes'>, so we have to tell how to decode bytes to str. See https://stackoverflow.com/a/21689447/822644

To handle non-latin letters, such as "č", some modifications had to be done in Javascript wrapper as well. btoa and atob both expect only latin letters. Usual trick is to use unescape(encodeURIComponent(letters)) in atob and decodeURIComponent(escape(bytes)) in btoa.

resolves "TypeError: write() argument must be str, not bytes"
resolves "InvalidCharacterError: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant