gpt4 book ai didi

python - 将 curl get to rest api 转换为 python

转载 作者:太空宇宙 更新时间:2023-11-04 02:03:14 24 4
gpt4 key购买 nike

我有这个 curl 命令:

curl -X GET --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Authorization: Token token=y_NbAkKc66ryYTWUXYEu' 'https://api.pagerduty.com/services?time_zone=UTC&sort_by=name'

我需要使用 requests 库将它转换为 python

import requests

def support(self):
services_list = requests.get('I need to convert the link to pass it here as a parameter')

最佳答案

import requests

def support():
headers = {
'Accept': 'application/vnd.pagerduty+json;version=2',
'Authorization': 'Token token=y_NbAkKc66ryYTWUXYEu'}

payloads = (
('time_zone', 'UTC'),
('sort_by', 'name'),)

services_list = requests.get('https://api.pagerduty.com/services', headers=headers, params=payloads)

关于python - 将 curl get to rest api 转换为 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55279690/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com