【问题标题】:Drive API Files Patch Method fails with "Precondition Failed" "conditionNotMet"驱动器 API 文件补丁方法失败,“前提条件失败”“conditionNotMet”
【发布时间】:2013-08-25 05:06:52
【问题描述】:

似乎一夜之间,Google Drive API 方法 files().patch( , ).execute() 已经停止工作并引发异常。如果您“尝试一下”,也可以通过 Google 的参考页面https://developers.google.com/drive/v2/reference/files/patch 观察到这个问题。

异常响应为:

500 Internal Server Error

cache-control:  private, max-age=0
content-encoding:  gzip
content-length:  162
content-type:  application/json; charset=UTF-8
date:  Thu, 22 Aug 2013 12:32:06 GMT
expires:  Thu, 22 Aug 2013 12:32:06 GMT
server:  GSE

    {
     "error": {
      "errors": [
       {
        "domain": "global",
        "reason": "conditionNotMet",
        "message": "Precondition Failed",
        "locationType": "header",
        "location": "If-Match"
       }
      ],
      "code": 500,
      "message": "Precondition Failed"
     }
    }

这确实影响了我们的应用程序。

【问题讨论】:

    标签: google-app-engine google-drive-api


    【解决方案1】:

    似乎在过去 24 小时内的某个时间,Files.Patch 问题已恢复到它在 8 月 22 日之前的工作方式。 每当我们尝试修补文件的 LastModified 时间戳时,我们也会遇到此问题 - 请参阅下面的日志文件摘录:

    20130826 13:30:45 - GoogleApiRequestException: retry number 0 for file patch of File/Folder Id 0B9NKEGPbg7KfdXc1cVRBaUxqaVk
    20130826 13:31:05 - ***** GoogleApiRequestException: Inner exception: 'System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
       at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
       at Google.Apis.Requests.Request.InternalEndExecuteRequest(IAsyncResult asyncResult) in c:\code.google.com\google-api-dotnet-client\default_release\Tools\BuildRelease\bin\Debug\output\default\Src\GoogleApis\Apis\Requests\Request.cs:line 311', Exception: 'Google.Apis.Requests.RequestError
    Precondition Failed [500]
    Errors [
        Message[Precondition Failed] Location[If-Match - header] Reason[conditionNotMet] Domain[global]
    ]
    '
    20130826 13:31:07 - ***** Patch file request failed after 0 tries for File/Folder 0B9NKEGPbg7KfdXc1cVRBaUxqaVk
    

    今天,只要修补文件时间戳,同一进程的运行就会成功,就像 8 月 22 日之前一样。

    由于这个 4/5 天的故障,我们现在有数百个(可能数千个)带有错误时间戳的文件。

    我知道 API 是测试版,但请 Google 开发人员“在任何‘试用修复’之前通知我们”,并至少在此论坛上发帖以确认问题,以节省我们尝试找出问题所在的时间用户程序。

    【讨论】:

      【解决方案2】:

      在此重复Getting 500: Precondition Failed when Patching a folder. Why?

      我记得一个开发视频中的一条评论说“使用更新而不是补丁,因为它在内部减少了一次服务器往返”。我由此推断 Patch 检查 etags 但 Update 没有。我已将代码更改为使用 Update 代替 Patch,此后该问题没有再次出现。

      一定喜欢针对移动的目标进行开发;-)

      【讨论】:

      • 使用更新而不是修补更可取,并且到目前为止对我有用。谢谢你的建议。谷歌没有关于修复 Patch() 或它为什么失败的消息。
      【解决方案3】:

      我们也遇到了这种情况。一个快速修复的解决方案是添加此标头:If-Match: *(理想情况下,您应该使用实体的 etag,但您现在可能没有解决冲突的逻辑)。

      Google 开发人员,如果您计划部署重大更改,请提前告知我们。

      【讨论】:

      • 感谢您的提示,我会考虑实施您的快速修复。您会认为 Google 会在部署更改之前运行单元测试。显然有什么东西从这里溜走了。
      猜你喜欢
      • 2017-01-08
      • 2015-12-23
      • 2018-08-12
      • 2011-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-17
      相关资源
      最近更新 更多