I have the following curl command which I can use to retrieve a list of users from a specific group in PagerDuty:
curl -H "Accept: application/vnd.pagerduty json;version=2" -H "Authorization: Token token=xxx" -X GET --data-urlencode "team_ids[]=abc" 'https://api.pagerduty.com/users'
How can I translate this exact command to run in a python get.requests() command? I can't seem to get it to work. This is what I'm currently trying but it doesn't filter on the group:
response = requests.get(
'https://api.pagerduty.com/users', params = {"data-urlencode": "team_ids[]=abc"}, headers={'Accept': 'application/vnd.pagerduty json;version=2','Authorization': 'Token token=xxx'}
)
)
Thanks!
CodePudding user response:
Simply omit --data-urlencode
from your params:
import requests
params = {
'team_ids[]':"abc",
"offset": '0',
}
headers = {
'Accept': 'application/vnd.pagerduty json;version=2',
'Authorization': 'Token token=xxx',
}
response = requests.get('https://api.pagerduty.com/users', params=params, headers=headers)
CodePudding user response:
if first solution is hard for you u can use one of websites that convert curl command to pytho/php etc ... code