You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently I'm using the BrickFTP python client to upload files to BrickFTP, the issue arises when I attempt to upload a file containing the character "\u2019", I get the following error:
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2019' in position 89154: Body ('’') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.
I already tried specifying the uft-8 encoding despite it being the default encoding the upload function on line 48 of client.py uses to no avail. After some research I found that the previously mentioned error is because the Requests library attempts to auto-encode what it's uploading based on the first 127 characters of the data. See: https://stackoverflow.com/questions/41030128/str-encoding-from-latin-1-to-utf-8-arbitrarily
I was able to solve this by modifying line 63 of client.py from this: resp = requests.put(upload_uri, data=input_file.read())
to this: resp = requests.put(upload_uri, data=input_file.read().encode(encoding))
I will be submitting a PR shortly.
The text was updated successfully, but these errors were encountered:
devyzr
pushed a commit
to devyzr/BrickFTP
that referenced
this issue
Jun 24, 2021
Currently I'm using the BrickFTP python client to upload files to BrickFTP, the issue arises when I attempt to upload a file containing the character "\u2019", I get the following error:
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2019' in position 89154: Body ('’') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.
I already tried specifying the uft-8 encoding despite it being the default encoding the upload function on line 48 of client.py uses to no avail. After some research I found that the previously mentioned error is because the Requests library attempts to auto-encode what it's uploading based on the first 127 characters of the data. See: https://stackoverflow.com/questions/41030128/str-encoding-from-latin-1-to-utf-8-arbitrarily
I was able to solve this by modifying line 63 of client.py from this:
resp = requests.put(upload_uri, data=input_file.read())
to this:
resp = requests.put(upload_uri, data=input_file.read().encode(encoding))
I will be submitting a PR shortly.
The text was updated successfully, but these errors were encountered: