MS Graph API在使用python的“用户更新过程”期间“无法转换原始值”

2024-09-30 00:28:16 发布

您现在位置:Python中文网/ 问答频道 /正文

目前,我可以在o365中创建用户并使用python脚本列出他们。在

我现在正在尝试运行一个非常简单的更新,但在应用使用位置时遇到问题(因此我也可以应用需要此操作的许可证),但当我执行此操作时,我收到以下错误:

{'error': {'code': 'Request_BadRequest', 'message': "Cannot convert a primitive value to the expected type 'Edm.Guid'. See the inner exception for more details.", 'innerError': {'date': '2019-08-06T18:51:25', 'request-id': '4e6c89c2-e3c6-xxxxx'}}}

显然它在寻找一些UID样式的条目,但是我填充的字段(根据api文档)是2个字符串。我的要求有误吗?在

这是我用于这个特定任务的代码。在

  # Update a user entry
  def updateUser(self,userupn,maildomain,usagelocation):
    userMail = userupn + '@' + maildomain
    header_params = {
      'Authorization': self.token_type + ' ' + self.access_token2,
      'Content-Type': 'application/json'
    }
    request_body = {
        #'accountEnabled': 'true',
        'usageLocation': usagelocation,
      }

    request_string = 'https://graph.microsoft.com/v1.0/' + userMail
    response = requests.post(request_string, data=json.dumps(request_body), headers=header_params)
    data = response.json()
    return data        

根据我在api文档中所看到的,应该足以将usageLocation设置为“US”或其他两个字母的值。在


Tags: the文档selfapijsondatarequesttype
1条回答
网友
1楼 · 发布于 2024-09-30 00:28:16

所以,问题是一些问题,我能够解决它们。这是我现在要做的工作。如果有人在我后面有类似的问题。 问题的简短版本是我正在使用请求.post()而不是请求.patch(). 在

  # Update a user entry
  def updateUser(self,userupn,maildomain,usagelocation):
    userMail = userupn + '@' + maildomain
    header_params = {
      'Authorization': self.token_type + ' ' + self.access_token2,
      'Content-Type': 'application/json'
    }
    request_body = {
        'accountEnabled': 'true',
        'passwordPolicies': 'DisablePasswordExpiration',
        'usageLocation': usagelocation,
        'country': usagelocation,
        'officeLocation': usagelocation,
      }

    request_string = 'https://graph.microsoft.com/v1.0/users/' + userMail
    response = requests.patch(request_string, data=json.dumps(request_body), headers=header_params)
    return response

相关问题 更多 >

    热门问题