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

"UnicodeEncodeError: 'latin-1' codec can't encode character, ordinal not in range" on GCS upload_object_via_stream #1802

Open
yagodorea opened this issue Nov 23, 2022 · 0 comments

Comments

@yagodorea
Copy link

Summary

I'm trying to upload some CSV files to GCS using libcloud, today I this error:

UnicodeEncodeError: 'latin-1' codec can't encode character '\u201c' in position 628: ordinal not in range(256)

Detailed Information

The encode character and position change with each run, even though the files don't change. I'm not sure what's causing that, CSV files are basically plaintext.

Here's the full stack (some internal code ommitted):

Traceback (most recent call last):
  [...]
    self.__container.upload_object_via_stream(stream, name)  # type: ignore
  File "/usr/local/lib/python3.8/site-packages/libcloud/storage/base.py", line 227, in upload_object_via_stream
    return self.driver.upload_object_via_stream(
  File "/usr/local/lib/python3.8/site-packages/libcloud/storage/drivers/s3.py", line 843, in upload_object_via_stream
    return self._put_object(
  File "/usr/local/lib/python3.8/site-packages/libcloud/storage/drivers/s3.py", line 1007, in _put_object
    result_dict = self._upload_object(
  File "/usr/local/lib/python3.8/site-packages/libcloud/storage/base.py", line 874, in _upload_object
    response = self.connection.request(
  File "/usr/local/lib/python3.8/site-packages/libcloud/common/base.py", line 659, in request
    return request_to_be_executed(
  File "/usr/local/lib/python3.8/site-packages/libcloud/common/base.py", line 678, in _retryable_request
    self.connection.prepared_request(
  File "/usr/local/lib/python3.8/site-packages/libcloud/http.py", line 260, in prepared_request
    self.response = self.session.send(
  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 440, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/local/lib/python3.8/http/client.py", line 1256, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.8/http/client.py", line 1302, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.8/http/client.py", line 1251, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.8/http/client.py", line 1040, in _send_output
    for chunk in chunks:
  File "/usr/local/lib/python3.8/http/client.py", line 999, in _read_readable
    datablock = datablock.encode("iso-8859-1")
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2019' in position 5251: ordinal not in range(256)

I'm running this from inside a k8s pod in a GKE cluster, trying to write to a GCS bucket.

apache-libcloud version: 3.5.1
python version: 3.8.15
pod image: python:3.8-slim

I'm not sure what are the steps to reproduce it. It's a CSV file generated by pulling some BigQuery schema metadata. It works locally, but when I ran it in the pod it raised this error.

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