简体   繁体   中英

convert curl get to rest api to python

I have this curl command:

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'

I need to convert it to python using requests library

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM