2

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!

Gary Turner
  • 189
  • 9
  • Why are you concatenating the URL with the string "0" in your python get request? For one, you can just restate it as `str(0)` instead of `str(int(0))` and you don't seem to be using an offset param in your curl command. – Siesmic_ Nov 24 '22 at 18:21

2 Answers2

2

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)
Lord Elrond
  • 13,430
  • 7
  • 40
  • 80
0

if first solution is hard for you u can use one of websites that convert curl command to pytho/php etc ... code

curlconverter.com

https://sqqihao.github.io/trillworks.html

https://www.scrapingbee.com/curl-converter/python/

urek mazino
  • 130
  • 12