I need to update python script to work with additional data which are not there at the moment. Hence the use of "requests" but somehow it's not working for me.
Basically I need python version of below curl which is providing data I need e.g.:
curl -X GET -H "Authorization: GenieKey XXXXXXXXXXXXXXX" 'https://api.eu.opsgenie.com/v2/alerts/f013a45e-4227-44bb-a0a7-9b2cb6c7c2d9-1616676741714?identifierType=id'
{
"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"
}
Part of the python script I need to create looks like this for now:
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)
Result I am getting:
root@server: pts/0: 2 files -> python3 get_request2.py
<Response [422]>
{
"message":"Key format is not valid!",
"took":0.001,
"requestId":"cc21637d-c864-4ba0-92a6-e454ddb74663"
}
Can you please help to determine why I am not getting the data as it is working from shell via curl? I tried to find similar topics but no solution for working for me. I tried add headers or verify=False but no success. Sensitive info is hidden. Source data are in JSON if it matters and python version is 3.4.10 Thank you in advance for any advice