Python ';不支持OData请求';使用outlook rest api更新联系人时出错
我正在尝试使用outlook rest更新exchange online中的联系人 应用程序编程接口。我可以使用post创建联系人。我也做了测试 这是工作正常的补丁。也就是说,当我发送Python ';不支持OData请求';使用outlook rest api更新联系人时出错,python,python-requests,exchangewebservices,contacts,office365api,Python,Python Requests,Exchangewebservices,Contacts,Office365api,我正在尝试使用outlook rest更新exchange online中的联系人 应用程序编程接口。我可以使用post创建联系人。我也做了测试 这是工作正常的补丁。也就是说,当我发送PUT请求时,它不起作用 这是我的代码: def update_contacts(): # / ContactsFolders/{folder_id}/contacts contact_id = "AAMkADAzNTg5ZjFmLWI2OTItNDFiOC1iNzg5LTNmOTJmOGUxYmU
PUT
请求时,它不起作用
这是我的代码:
def update_contacts():
# / ContactsFolders/{folder_id}/contacts
contact_id = "AAMkADAzNTg5ZjFmLWI2OTItNDFiOC1iNzg5LTNmOTJmOGUxYmUxNwBGAAAAAABMzp004WaZQqK4q_HRlSK9BwAqlNNaGOnjR7gnbsbOcpkFAAJm6kCDAAAqlNNaGOnjR7gnbsbOcpkFAAJm6m_3AAA="
url = "https://outlook.office365.com/api/v2.0/users('{email_id}')/contacts/{contact_id}"
#data = {"GivenName": "C1_Updated_put", "DisplayName": "MyRestApiContactFolder1"}
data = {
"Categories": [],
"Birthday": None,
"FileAs": "",
"DisplayName": "MyRestApiContactFolder1",
"GivenName": "C1_Using_Put",
"Initials": None,
"MiddleName": None,
"NickName": None,
"Surname": None,
"Title": None,
"YomiGivenName": None,
"YomiSurname": None,
"YomiCompanyName": None,
"Generation": None,
"ImAddresses": [],
"JobTitle": None,
"CompanyName": None,
"Department": None,
"OfficeLocation": None,
"Profession": None,
"BusinessHomePage": None,
"AssistantName": None,
"Manager": None,
"HomePhones": [],
"MobilePhone1": None,
"BusinessPhones": [],
"SpouseName": None,
"PersonalNotes": "",
"Children": [],
"EmailAddresses": [],
"HomeAddress": {
"Type": "Unknown"
},
"BusinessAddress": {
"Type": "Unknown"
},
"OtherAddress": {
"Type": "Unknown"
}
}
req = url.format(email_id=email_id, contact_id=contact_id)
resp = requests.put(url=req, json=data, headers=HEADERS)
#print(HEADERS)
print(resp)
resp = resp.json()
print(resp)
这是我请求的标题-
def set_headers():
global HEADERS
token_resp = get_token(email_id).json()
access_token = token_resp.get('access_token')
HEADERS['Authorization'] = 'Bearer '+ access_token
HEADERS["content-type"] = "application/json"
HEADERS['accept'] = "application/json"
HEADERS['X-AnchorMailbox'] = email_id
#print(HEADERS)
这是使用打印语句的响应(405)
:
<Response [405]> {u'error': {u'message': u'The OData request is not
supported.', u'code': u'ErrorInvalidRequest'}}
{u'error':{u'message':u'OData请求不正确
支持。“,u'code”:u'ErrorInvalidRequest'}
根据他们的文档,您需要使用补丁方法更新:。根据他们的文档,您需要使用补丁方法更新:。您确定服务器接受PUT
请求吗?它可能不会,因此您会出错。您确定服务器接受PUT
请求吗?它可能没有,因此你的错误。