Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requests attempts to autoencode PUT request on line 63 of client.py #8

Open
devyzr opened this issue Jun 24, 2021 · 0 comments
Open

Comments

@devyzr
Copy link

devyzr commented 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.

devyzr pushed a commit to devyzr/BrickFTP that referenced this issue Jun 24, 2021
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

No branches or pull requests

1 participant