2
我需要在Google Drive中使用requests
python库创建一个新文件。Drive API - 解析错误插入文件
r = requests.post(
'https://www.googleapis.com/drive/v2/files',
headers={
'Content-type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer %s' % access_token
}
)
此代码可以成功创建一个文件,并将所有值设置为默认值,但如果我尝试例如设置文件的标题:
r = requests.post(
'https://www.googleapis.com/drive/v2/files',
data={"title": "Foo"},
headers={
'Content-type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer %s' % self.access_token
}
)
然后服务器400 Bad Request
和JSON响应响应:
{
"error": {
"code": 400,
"message": "Parse Error",
"errors": [
{
"domain": "global",
"message": "Parse Error",
"reason": "parseError"
}
]
}
}
什么我做错了,如何解决呢?