【发布时间】:2014-05-11 15:32:30
【问题描述】:
我正在尝试使用 python 请求库将文件发送到 Google Drive api。根据谷歌文档,我唯一需要它来发送多部分请求 https://developers.google.com/drive/web/manage-uploads#multipart 我需要先发送元数据,然后再发送文件。这是我到目前为止所尝试的
def upload_csv(self, file, description):
self.refresh()
url = self.url+'?uploadType=multipart&' + urllib.urlencode({'key':self.api_key})
headers = { 'Authorization':'Bearer {}'.format(self.access_token),
# 'content-type':'multipart/related',
# 'content-length':size
}
data = {'title':file,'description':description }
files = {'file':(file,open(file,'rb'),'text/csv')}
response = requests.post( url, headers = headers, data = data, files = files )
但我得到一个错误:u'Bad content type。请使用多部分。 有没有办法使用请求发送元数据和文件
【问题讨论】:
-
这是
requests的哪个版本? 2.x 已经产生了一个兼容的请求。
标签: python google-api python-requests