微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python GET 请求错误 422密钥格式无效

如何解决python GET 请求错误 422密钥格式无效

我需要更新 python 脚本以处理目前不存在的其他数据。因此使用“请求”但不知何故它对我不起作用。

基本上我需要下面 curl 的 python 版本,它提供我需要的数据,例如:

curl -X GET -H "Authorization: GenieKey XXXXXXXXXXXXXXX" 'https://api.eu.opsgenie.com/v2/alerts/f013a45e-4227-44bb-a0a7-9b2cb6c7c2d9-161661467417 '

{
   "data":{
      "seen":true,"id":"f013a45e-4227-44bb-a0a7-9b2cb6c7c2d9-1616676741714","tinyId":"400","alias":"test MP","message":"MP testing","status":"open","ackNowledged":true,"isSeen":true,"tags":[
         "MP testing","sre"
      ],"snoozed":false,"count":1,"lastOccurredAt":"2021-03-25T12:52:21.714Z","createdAt":"2021-03-25T12:52:21.714Z","updatedAt":"2021-04-16T10:28:18.372Z","source":"mail@mail.no","owner":"mail@mail.no","priority":"P5","teams":[
         {
            "id":"45c719c5-d3e1-4e75-9284-b0c75103d44a"
         }
      ],"responders":[
         {
            "type":"team","id":"45c719c5-d3e1-4e75-9284-b0c75103d44a"
         }
      ],"integration":{
         "id":"132f80a5-b653-4b8a-ba33-eed59cfd6a0a","name":"Default API","type":"API"
      },"report":{
         "ackTime":1892156658,"ackNowledgedBy":"mail@mail.no"
      },"ownerTeamId":"45c719c5-d3e1-4e75-9284-b0c75103d44a","actions":[
         
      ],"entity":"TEST MP","description":"popis problemu {{priority}}","details":{
         "priority2":"jednicka","issueKey":"FIXIT-981939"
      }
   },"took":0.005,"requestId":"b1f0f485-b06e-45f2-88c0-fe5809cd1ea9"
}

我现在需要创建的部分 python 脚本如下所示:

import requests

from requests.auth import HTTPBasicAuth


# Making a get request
response = requests.get('https://api.eu.opsgenie.com/v2/alerts/f013a45e-4227-44bb-a0a7-9b2cb6c7c2d9-1616676741714?identifierType=id',auth=('Correct ID','Correct PW'))

print(response.text)              # To print unicode response string
print(response)

我得到的结果:

root@server: pts/0: 2 个文件 -> python3 get_request2.py

<Response [422]>
{
   "message":"Key format is not valid!","took":0.001,"requestId":"cc21637d-c864-4ba0-92a6-e454ddb74663"
}

你能帮助确定为什么我没有得到数据,因为它是通过 curl 从 shell 工作的吗?我试图找到类似的主题,但没有为我工作的解决方案。我尝试添加标题或 verify=False 但没有成功。敏感信息被隐藏。 如果重要,源数据采用 JSON 格式,python 版本为 3.4.10 预先感谢您的任何建议

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。