MediaFileUpload of HTML in UTF-8 encoding using Python and Google-Drive-SDK

Posted by Victoria on Stack Overflow See other posts from Stack Overflow or by Victoria
Published on 2013-10-20T03:51:15Z Indexed on 2013/10/20 3:53 UTC
Read the original article Hit count: 256

Looking for example using MediaFileUpload has a reference to the basic documentation for creating/uploading a file to Google Drive.

However, while I have code that creates files, converting from HTML to Google Doc format. It works perfectly when they contain only ASCII characters, but when I add a non-ASCII character, it fails, with the following traceback:

Traceback (most recent call last):
  File "d:\my\py\ckwort.py", line 949, in <module>
    rids, worker_documents = analyze( meta, gd )
  File "d:\my\py\ckwort.py", line 812, in analyze
    gd.mkdir( **iy )
  File "d:\my\py\ckwort.py", line 205, in mkdir
    self.create( **( kw['subop']))
  File "d:\my\py\ckwort.py", line 282, in create
    media_body=kw['media_body'],
  File "D:\my\py\gdrive2\oauth2client\util.py", line 120, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "D:\my\py\gdrive2\apiclient\http.py", line 676, in execute
    headers=self.headers)
  File "D:\my\py\gdrive2\oauth2client\util.py", line 120, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "D:\my\py\gdrive2\oauth2client\client.py", line 420, in new_request
    redirections, connection_type)
  File "D:\my\py\gdrive2\httplib2\__init__.py", line 1597, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "D:\my\py\gdrive2\httplib2\__init__.py", line 1345, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "D:\my\py\gdrive2\httplib2\__init__.py", line 1282, in _conn_request
    conn.request(method, request_uri, body, headers)
  File "C:\Python27\lib\httplib.py", line 958, in request
    self._send_request(method, url, body, headers)
  File "C:\Python27\lib\httplib.py", line 992, in _send_request
    self.endheaders(body)
  File "C:\Python27\lib\httplib.py", line 954, in endheaders
    self._send_output(message_body)
  File "C:\Python27\lib\httplib.py", line 812, in _send_output
    msg += message_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 370: ordinal not in range(128)

I don't find any parameter to use to specify what file encoding should be used by MediaFileUpload (My files are using UTF-8). Am I missing something?

© Stack Overflow or respective owner

Related posts about python

Related posts about utf-8