简体   繁体   English

为什么在Google Colaboratory中使用Python3.6在google drive.files.update中出现“错误请求”?

[英]Why “Bad request” in google drive.files.update using Python3.6 in Google Colaboratory?

I use Google Drive API v3 and Python3.6 in Google Colaboratory. 我在Google合作实验室中使用了Google Drive API v3和Python3.6。 My guess, it is an error in update_metadata, but I can't find it. 我的猜测是update_metadata中的错误,但我找不到它。 https://developers.google.com/drive/api/v3/reference/files/update says these properties are writable. https://developers.google.com/drive/api/v3/reference/files/update说这些属性是可写的。 I'm stucked, and I need help, thanks. 我被困住了,需要帮助,谢谢。

def NEWshare(selected_id, email, permissions_metadata, emailmsg, send=True):                   
    drive_service.permissions().create(body=permissions_metadata,                                            
    emailMessage = emailmsg,
    sendNotificationEmail = send,
    fileId=selected_id).execute()

def NEWupdate(selected_id, update_metadata):
    drive_service.files().update(body=update_metadata, 
    fileId=selected_id).execute()

permissions_metadata = {
                        "deleted": True,
                        "emailAddress": email,
                        "kind": "drive#permission",
                        "role": "reader",
                        "type": "user"
                       }

update_metadata = {
                   "copyRequiresWriterPermission": True,
                   "writersCanShare": False
                  }

The NEWshare(selected_id, email, permissions_metadata, emailmsg, send=True) works well. NEWshare(selected_id,电子邮件,permissions_metadata,emailmsg,send = True)效果很好。 Now I want to update with NEWupdate(selected_id, update_metadata), but I obtain the error message 现在我想用NEWupdate(selected_id,update_metadata)更新,但是我得到了错误消息

HttpError                                 Traceback (most recent call last)
<ipython-input-26-07b373587193> in <module>()
----> 1 NEWupdate(selected_id, update_metadata)

2 frames
/usr/local/lib/python3.6/dist-packages/googleapiclient/http.py in execute(self, http, num_retries)
    838       callback(resp)
    839     if resp.status >= 300:
--> 840       raise HttpError(resp, content, uri=self.uri)
    841     return self.postproc(resp, content)
    842 

HttpError: <HttpError 400 when requesting https://www.googleapis.com/drive/v3/files/1n8k_4fY4KMM9gnqD2MPvvV8cRgY0yCRd?alt=json returned "Bad Request">

For this error " HttpError: <HttpError 400 when requesting https://www.googleapis.com/drive/v3/files/1n8k_4fY4KMM9gnqD2MPvvV8cRgY0yCRd?alt=json returned "Bad Request"> ", a refresh request needs refresh_token , client_id , client_secret , and grant_type . 对于此错误“ HttpError: <HttpError 400 when requesting https://www.googleapis.com/drive/v3/files/1n8k_4fY4KMM9gnqD2MPvvV8cRgY0yCRd?alt=json returned "Bad Request"> ”时,刷新请求需要refresh_tokenclient_idclient_secret ,和grant_type Here is the documentation on refreshing an access token . 这是有关刷新访问令牌的文档。 See this github post . 请参阅此github帖子

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Colaboratory 中的 Python - 如何在 Google Drive 中创建、写入和读取文件 - Python in Google Colaboratory - How to create, write and read files in google drive Google Team Drive和Google协作下载/上传文件 - Google team drive and google colaboratory downloading/uploading files 使用Anaconda安装Python3.6时出现问题 - Problems installing Python3.6 using Anaconda 使用我在 Google Cloud VM 上全新安装的 Python3.6 创建的虚拟环境 - Use the virtual environment created by my fresh install of Python3.6 on Google Cloud VM 在 Solaris 上使用 Python3.6 调查shutil 调用中的“错误系统调用” - Investigate “Bad System Call” on shutil calls with Python3.6 on Solaris 如何在单个请求中使用 Python 在 Google Drive 中上传文件夹(不是文件)? - How do I upload a folder (not files) in Google Drive using Python at a single request? 使用 google colaboratory 过滤相同的标签图像并在谷歌驱动器中保存另一个文件夹 - Filter same tag images and save another folder at google drive using google colaboratory 为什么多处理不能与 python dash 框架一起使用 - Python3.6 - Why is multiprocessing not working with python dash framework - Python3.6 如何使用 Python 在 Google Drive 上的文件夹中搜索文件 - how to search the files inside the folders on Google Drive using Python python中无法使用Google Drive上传文件 API - Unable to upload files using Google Drive API in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM