Diese Frage ist immer noch ungelöst! Bitte antworten Sie, wenn Sie wissen
Fehler
Ich habe hier einen Fehler gemeldet
http://code.google.com/p/google-api-python-client/issues/detail?id=131&thanks=131&ts=1335708962
Während der Arbeit an meinem gdrive-cli Projekt bin ich auf diesen Fehler gestoßen, als ich versucht habe, eine UTF-8 Markdown-Datei mit dem Mime-Type "text/plain" hochzuladen. Ich habe es auch mit "text/plain;charset=utf-8" versucht und das gleiche Ergebnis erhalten.
Hier ist der Stacktrace, den ich erhalten habe:
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)
Und der Befehl, den ich geben musste, um ihn zu erzeugen, lautete:
gdrive-cli --insert README.md "readme file" none "text/plain" README.md
Sie können die genaue README.md-Datei zum Zeitpunkt des Auftretens dieses Problems hier abrufen, http://tomdignan.com/files/README.md
Es folgt der entsprechende Code aus den SDK-Beispielen. Die Parameter werden in dieser Reihenfolge eingegeben:
eine Dienstinstanz, "README.md", "readme file", None (Python-Schlüsselwort), "text/plain", und "README.md"
def insert_file(service, title, description, parent_id, mime_type, filename):
"""Insert new file.
Args:
service: Drive API service instance.
title: Title of the file to insert, including the extension.
description: Description of the file to insert.
parent_id: Parent folder's ID.
mime_type: MIME type of the file to insert.
filename: Filename of the file to insert.
Returns:
Inserted file metadata if successful, None otherwise.
"""
media_body = MediaFileUpload(filename, mimetype=mime_type)
body = {
'title': title,
'description': description,
'mimeType': mime_type
}
# Set the parent folder.
if parent_id:
body['parentsCollection'] = [{'id': parent_id}]
try:
file = service.files().insert(
body=body,
media_body=media_body).execute()
# Uncomment the following line to print the File ID
# print 'File ID: %s' % file['id']
return file
except errors.HttpError, error:
print "TRACEBACK"
print traceback.format_exc()
print 'An error occured: %s' % error
return None