kulpa / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

When attempting to upload a UTF-8 text file with the Google Drive SDK for python, I get a UnicodeDecodeError #131

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Attempt to upload a UTF-8 file with MediaFileUpload

What is the expected output? What do you see instead?

Expected: Inserted <file_id>
Instead:

Traceback (most recent call last):
  File "./gdrive-cli", line 155, in <module>
    handle_args(args)
  File "./gdrive-cli", line 92, in handle_args
    handle_insert(args.insert)
  File "./gdrive-cli", line 126, in handle_insert
    filename)
  File "/home/tom/Github/gdrive-cli/gdrive/gdrive.py", line 146, in insert_file
    media_body=media_body).execute()
  File "/usr/local/lib/python2.7/dist-packages/apiclient/http.py", line 393, in execute
    headers=self.headers)
  File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 401, in new_request
    redirections, connection_type)
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1544, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1294, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1231, in _conn_request
    conn.request(method, request_uri, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 955, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 989, in _send_request
    self.endheaders(body)
  File "/usr/lib/python2.7/httplib.py", line 951, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 809, in _send_output
    msg += message_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 4518: 
ordinal not in range(128)

What version of the product are you using? On what operating system?

tom@tralfamadore ~/Github/tom-dignan.github.com $ pip search 
google-api-python-client
google-api-python-client  - Google API Client Library for Python
  INSTALLED: 1.0beta8 (latest)

Please provide any additional information below

I have attached a patch that fixes this, but I am not sure if it's the right 
way. I hope it helps.

Also see my stackoverflow post

http://stackoverflow.com/questions/10372370/when-attempting-to-upload-a-utf-8-te
xt-file-with-the-google-drive-sdk-for-python/10372740#10372740

Original issue reported on code.google.com by tom.dig...@gmail.com on 29 Apr 2012 at 2:16

Attachments:

GoogleCodeExporter commented 9 years ago
actually I jumped the gun, that patch doesn't fix anything. The bug still 
stands, though.

Original comment by tom.dig...@gmail.com on 29 Apr 2012 at 2:25

GoogleCodeExporter commented 9 years ago
There's been several fixes for encoding issues since the beta8 release. Please 
try pulling google-api-python-client from the head of mercurial and install 
that and see if it fixes the problem.

Original comment by jcgregorio@google.com on 30 Apr 2012 at 3:33

GoogleCodeExporter commented 9 years ago
httplib simplistically tests for a string body for efficiency.  Might try 
testing with httplib.py lines 808, 809 and 810 commented.

Original comment by lar...@winfirst.com on 30 Apr 2012 at 10:43

GoogleCodeExporter commented 9 years ago
I was finally able to reproduce this bug locally. The fix has been submitted in:

http://code.google.com/p/google-api-python-client/source/detail?r=efd0ccd31d6c16
ddf9f65ba5c31c7033749be0e1

Original comment by jcgregorio@google.com on 6 Dec 2012 at 8:48

GoogleCodeExporter commented 9 years ago
Thanks! I really had no idea how to fix it. I'll try the new code this weekend!

Original comment by tom.dig...@gmail.com on 6 Dec 2012 at 10:43

GoogleCodeExporter commented 9 years ago
Please update PyPI (https://pypi.python.org/pypi/google-api-python-client). It 
currently shows that the last upload was done in September.

Original comment by myselfasunder@gmail.com on 26 Feb 2013 at 4:44

GoogleCodeExporter commented 9 years ago
@myselfasunder, feel free to file a new issue with the request.

Original comment by dhermes@google.com on 26 Feb 2013 at 5:09