[英]Translate curl command to python requests.get
I have the following curl command which I can use to retrieve a list of users from a specific group in PagerDuty:我有以下 curl 命令,可用于从 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?我如何翻译这个确切的命令以在 python get.requests() 命令中运行? 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!谢谢!
Simply omit --data-urlencode
from your params:只需从您的参数中省略
--data-urlencode
:
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)
if first solution is hard for you u can use one of websites that convert curl command to pytho/php etc... code如果第一个解决方案对你来说很难,你可以使用一个将 curl 命令转换为 pytho/php 等的网站...代码
curlconverter.com curlconverter.com
https://sqqihao.github.io/trillworks.html https://sqqihao.github.io/trillworks.html
https://www.scrapingbee.com/curl-converter/python/ https://www.scrapingbee.com/curl-converter/python/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.