- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用适用于 Python 的 Google API 客户端库来重命名驱动文件,这里是重命名函数:
def rename_file(service, file_id, new_title):
"""Rename a file.
Args:
service: Drive API service instance.
file_id: ID of the file to rename.
new_title: New title for the file.
Returns:
Updated file metadata if successful, None otherwise.
"""
try:
file = {'title': new_title}
# Rename the file.
updated_file = service.files().patch(
fileId=file_id,
body=file,
fields='title').execute()
return updated_file
except errors.HttpError, error:
logging.error('An error occurred: %s' % error)
return None
但是得到错误,这里是trackback:
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/myproduct/libs/oauth2client/appengine.py", line 469, in check_oauth
return method(request_handler, *args, **kwargs)
File "/myproduct/main.py", line 31, in get
new_title="file new name")
File "/myproduct/gapi.py", line 148, in rename_file
fields='title').execute()
File "/myproduct/libs/oauth2client/util.py", line 120, in positional_wrapper
return wrapped(*args, **kwargs)
File "/myproduct/libs/apiclient/http.py", line 676, in execute
headers=self.headers)
File "/myproduct/libs/oauth2client/util.py", line 120, in positional_wrapper
return wrapped(*args, **kwargs)
File "/myproduct/libs/oauth2client/client.py", line 420, in new_request
redirections, connection_type)
File "/myproduct/libs/httplib2/__init__.py", line 1588, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/myproduct/libs/httplib2/__init__.py", line 1336, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/myproduct/libs/httplib2/__init__.py", line 1273, in _conn_request
conn.request(method, request_uri, body, headers)
File "/myproduct/libs/httplib2/__init__.py", line 1112, in request
validate_certificate=self.validate_certificate)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/urlfetch.py", line 265, in fetch
allow_truncated, follow_redirects, validate_certificate)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/urlfetch.py", line 286, in make_fetch_call
raise InvalidMethodError('Invalid method %s.' % str(method))
InvalidMethodError: Invalid method PATCH.
那么直接使用rename_file函数应该怎么做呢?
最佳答案
如错误消息所示,urlfetch
尚不支持 PATCH
,但是 issue已向 App Engine 团队提交并确认该问题。
与此同时,您可以修补 httplib2
以发送 X-HTTP-METHOD-OVERRIDE
header ,而不是使用 PATCH
方法,如补丁中所示 filed针对 httplib2
。
由于该补丁引用了一些旧代码,因此我在此处提供了相关代码段:
UNAUTHORIZED_METHODS = ['patch']
HTTP_METHOD_OVERRIDE_HEADER = 'X-HTTP-Method-Override'
HTTP_OVERRIDE_METHOD = 'POST'
class AppEngineHttpConnection(httplib.HTTPConnection):
...
def request(self, method, url, body=None, headers={}):
if method.lower() in UNAUTHORIZED_METHODS:
# No side-effects on provided headers.
new_headers = {}
new_headers.update(headers)
new_headers[HTTP_METHOD_OVERRIDE_HEADER] = method
method = HTTP_OVERRIDE_METHOD
headers = new_headers
super(AppEngineHttpConnection, self).request(method, url, body, headers)
由于 request
现在只是在 httplib.HTTPConnection
中定义的那个,我们可以在更改我们需要的一个 header 的同时重新使用它。
HTTPS
版本需要类似的覆盖,因为它不继承自 AppEngineHttpConnection
。
关于python - 如何在 App Engine 上将 PATCH 方法与适用于 Python 的 Google API 客户端库一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14107336/
我正在尝试使用 Android SDK 中的 Draw9Patch 工具,但在使用 Draw9Patch 打开我的图像后,它立即将我的所有图像区域显示为“坏补丁”。我手动绘制了定义可拉伸(stretc
我有一个运行补丁命令的构建工具,如果补丁命令返回非零值,它将导致构建失败。我正在应用一个可能已经或可能尚未应用的补丁,所以我使用 -N选项 patch ,它应该跳过。但是,当它确实跳过时,patch返
patching file chrome/browser/gpu_process_host_ui_shim.cc Unreversed patch detected! Skipping patch.
尝试查看哪些模型最适合api(更新少,但对象结构可能经常更改,高读取应用程序) 我有这样的资源 Epic(ID、名称、描述、开始日期、结束日期、状态、故事) 故事(ID、名称、说明、开始日期、结束日期
我创建了新问题,因为我觉得上一个问题已经得到解答,这属于一个新的地方。 我跑 bitbake core-image-minimal我收到以下错误: ERROR: systemd-1_232-r0 do
我正在使用 ColdFusion 10 与 PayPal 的服务器和 for some requests 进行通信我需要执行 HTTP PATCH 请求 are not supported by CF
我试图了解这两种模拟方法之间的区别。有人可以帮助区分它们吗?对于这个例子,我使用 passlib 库。 from passlib.context import CryptContext from un
WebTarget webTarget = httpClient.target(url); Invocation.Builder invocationBuilder = webTarget.reque
当提到“提交补丁”时,补丁这个词究竟是什么意思? 我已经看到它被大量使用,尤其是在开源世界中。它是什么意思,提交补丁到底涉及什么? 最佳答案 这是一个文件,其中列出了已更改的代码文件之间的差异。它通常
对于 matplotlib.patches,patch.contains_point(xy) 方法似乎与 patch.get_path().contains_point(xy) 不同,至少在拥有之后将
这是什么RFC 5789说: The PATCH method requests that a set of changes described in the request entity be ap
在 Draw 9-patch 中,一切看起来都很好。 但是,我的 SDK 说 9-patch png 格式不正确。因为我有类似 11-patch png 的东西。因为我不希望小抓取区域被缩放。如何让它
我创建了一个使用 javax.xml.ws.Endpoint 来创建 REST 端点的类: @WebServiceProvider @ServiceMode(value = javax.xml.ws.
语境 我有一个 spring boot (version 2.2.6.RELEASE) web 项目。 从这个 Web 应用程序(我称之为“APP1”)我想使用来自另一个 Web 应用程序的 PATC
在为我的应用程序编写单元测试时,我一直使用 @mock.patch 和 @patch.object 装饰器。但是现在,当我使用装饰器进行一些单元测试时,我收到错误消息“TypeError: stati
我在使用@mock.patch.object 函数时观察到 nosetests 的一个非常奇怪的行为: 当我同时运行多个测试时,我得到的结果与单独运行它们时不同。具体来说,在某些情况下,当我一起运行多
我正在使用 RestSharp v107。 我想更新测试用例的迭代路径。我可以使用 Postman 更新它,但使用 RestSharp 我收到“BAD Request”-“您必须在请求正文中传递有效的
我已经阅读了 GNU 项目中关于开源和其他许可证的文章。某些许可证允许您将更改发布为补丁,而不是完整的源代码(例如 Q 公共(public)许可证或 gnuplot 许可证)。这是什么意思?这样的补丁
有谁知道免费的优质补丁程序?您知道,可以将其中包含旧程序的目录放入其中,然后将其与具有新版本的目录进行比较,然后吐出一个补丁,这仅仅是两者之间的区别? 另外,我正在寻找可以修补整个目录的东西,而不仅仅
由于我当时一直在使用 Subversion 和 shell 工具,git-gui这些都是不可能的。是否有任何 shell 工具可以交互式地逐行应用补丁? 最佳答案 尝试通过 --dry-run选项 p
我是一名优秀的程序员,十分优秀!