gpt4 book ai didi

python - 批量删除联系人报 "If-Match or If-None-Match header or entry etag attribute required"错误

转载 作者:太空狗 更新时间:2023-10-29 18:08:13 26 4
gpt4 key购买 nike

我正在使用 gdata Python 库来批量删除联系人,但我只是收到“需要 If-Match 或 If-None-Match header 或条目 etag 属性”错误。

我认为当我必须在控制台中启用 Contacts API 时问题就开始了(直到几天前还不需要?*)。

编辑:

更新和删除操作实际上都失败了。批量插入工作正常。

尝试指定 If-Match header ,但仍然失败:

custom_headers = atom.client.CustomHeaders(**{'If-Match': '*'})
request_feed = gdata.contacts.data.ContactsFeed()
request_feed.AddDelete(entry=contact, batch_id_string='delete')
response_feed = self.gd_client.ExecuteBatch(
request_feed,
'https://www.google.com/m8/feeds/contacts/default/full/batch',
custom_headers=custom_headers
)

还创建了一个 ticket在项目页面上,但我怀疑它会在那里引起任何关注。

编辑 2:

使用带有 force=TrueBatch 方法(它只是添加了 If-Match: * header )是相同的结果。

response_feed = self.gd_client.Batch(
request_feed,
uri='https://www.google.com/m8/feeds/contacts/default/full/batch',
force=True
)

* 有人可以验证吗?我以前从来不需要在控制台中启用它,我的应用程序能够毫无问题地使用 Contacts API,而且我相信它以前甚至不可用。昨天看的我很吃惊。

最佳答案

正在从 Google 代码票复制答案。

基本上,您需要修补客户端的 Post 方法来稍微修改请求提要。这是一种不直接修改库源代码的方法:

def patched_post(client, entry, uri, auth_token=None, converter=None, desired_class=None, **kwargs):
if converter is None and desired_class is None:
desired_class = entry.__class__
http_request = atom.http_core.HttpRequest()
entry_string = entry.to_string(gdata.client.get_xml_version(client.api_version))
entry_string = entry_string.replace('ns1', 'gd') # where the magic happens
http_request.add_body_part(
entry_string,
'application/atom+xml')
return client.request(method='POST', uri=uri, auth_token=auth_token,
http_request=http_request, converter=converter,
desired_class=desired_class, **kwargs)

# when it comes time to do a batched delete/update,
# instead of calling client.ExecuteBatch, instead directly call patched_post
patched_post(client_instance, entry_feed, 'https://www.google.com/m8/feeds/contacts/default/full/batch')

关于python - 批量删除联系人报 "If-Match or If-None-Match header or entry etag attribute required"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23576729/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com