PDClientError: PUT /incidents: API responded with non-success status (400)
vibhutigoel opened this issue · comments
We are using below function to resolve the incident
def resolve_incident(self, incident_ids):
for incident_id in incident_ids:
incident = self.session.rget("incidents/" + incident_id)
try:
if incident['status'] != 'resolved':
self.session.rput(
"incidents",
json=[{'id': incident_id, 'type': 'incident_reference', 'status': 'resolved'}]
)
else:
print "Incident: " + incident_id + " is already resolved!"
except PDClientError:
print "Could not resolve incident: " + incident_id
traceback.print_exc()
raise RuntimeError("Could not resolve incident: " + incident_id)
return True
suddenly its started throwing below error :
PDClientError: PUT /incidents: API responded with non-success status (400)
As per my finding there is some issue with rput
Is anything changes in the pagerduty API ? or in pdpyras ?
getting the same with rpost.
following the example from the README:
from pdpyras import APISession
api_token = 'your-token-here'
session = APISession(api_token)
payload = {
"type": "incident",
"title": "This is a test 4",
"service": {"id": "service_id", "type": "service_reference"},
"assignments": [{"assignee": {"id": "user_id", "type": "user_reference"}}],
}
pd_incident = session.rpost("incidents", json=payload)
return:
self.pagerDutyDedupKey = self.pagerDutySession.rpost("incidents", json=payload)
File "/usr/local/lib/python3.9/site-packages/pdpyras.py", line 146, in call
r = raise_on_error(method(self, path, **pass_kw))
File "/usr/local/lib/python3.9/site-packages/pdpyras.py", line 82, in raise_on_error
raise PDClientError("%s %s: API responded with non-success status "
pdpyras.PDClientError: POST incidents: API responded with non-success status (400)
ah works for me now, PD requires an extra header called from
for some calls, you can set it when instantiating the class. PagerDutyAPISession("apikey", default_from='test@useremail.com')
This is already noted in the README.
FYI, if more detail about a response is needed (i.e. validation errors), to make it easier to troubleshoot when using any of the methods that raise exceptions for non-2xx response statuses: the response
property of the exception, if non-None
, should be a requests.Response
object. The text
property / json()
method of such an object contains the body, which should contain errors reported by the API, if any.