How do I connect with Python to a RESTful API using keys instead of basic authentication username and password?

前端 未结 1 1072
鱼传尺愫
鱼传尺愫 2021-02-05 17:11

I am new to programming, and was asked to take over a project where I need to change the current Python code we use to connect to a Ver 1 RESTful API. The company has switched t

1条回答
  •  北荒
    北荒 (楼主)
    2021-02-05 17:51

    you can add HTTP headers to a request

    headers = {
        'X-ABC-API-ID': 'x-x-x-x-x',
        'X-ABC-API-KEY': 'nnnnnnnnnnnnnnnnnnnnnnn',
        'X-DE-API-ID': 'x',
        'X-DE-API-KEY': 'nnnnnnnnnnnnnnnnnnnnnnnn'
    }
    r = requests.get('https://www.somecompany.com/api/v2/groups/', headers=headers)
    

    0 讨论(0)
提交回复
热议问题