Drive API Files Patch Method fails with “Precondition Failed” “conditionNotMet”

余生颓废 提交于 2020-01-14 12:35:42

问题


It seems that over night the Google Drive API methods files().patch( , ).execute() has stopped working and throws an exception. This problem is also observable through Google's reference page https://developers.google.com/drive/v2/reference/files/patch if you "try it".

The exception response is:

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"
     }
    }

This is really impacting our application.


回答1:


duplicated here Getting 500: Precondition Failed when Patching a folder. Why?

I recall a comment from one of dev videos saying "use Update instead of Patch as it has one less server roundtrip internally". I've inferred from this that Patch checks etags but Update doesn't. I've changed my code to use Update in place of Patch and the problem hasn't recurred since.

Gotta love developing against a moving target ;-)




回答2:


We're experiencing this as well. A quick-fix solution is to add this header: If-Match: * (ideally, you should use the etag of the entity but you might not have a logic for conflict resolution right now).

Google Developers, please give us a heads up if you're planning to deploy breaking changes.




回答3:


Looks like sometime in the last 24 hours the Files.Patch issue has been put back to how it used to work as per Aug 22. We were also hitting this issue whenever we attempted to Patch the LastModified Timestamp of a file - see log file extract below:

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

Today's run of the same process is succeeding whenever it Patches a files timestamp, just as it was prior to Aug 22.

As a result of this 4/5 day glitch, we now have hundreds (possibly thousands) of files with the wrong timestamps.

I know the API is Beta but please, please Google Developers "let us know in advance of any 'trialing fixes'" and at least post in this forum to acknowledge the issue to save us time trying to find the fault in our user programs.



来源:https://stackoverflow.com/questions/18380942/drive-api-files-patch-method-fails-with-precondition-failed-conditionnotmet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!