Python 如何从具有帐户密钥的api获取请求

Python 如何从具有帐户密钥的api获取请求,python,api,Python,Api,输出 我也有一个api密钥api_-key='0x-x-x-x0在请求中是否有我可以提供的api_-key。像用户名和密码一样获取 headersheaders={'Content-type':'application/json','X-IG-API-KEY':'0x-X-X-x0'}中的示例这就是您要找的吗 import requests import json def test_request_response(): # Send a request to the API serv

输出

我也有一个api密钥
api_-key='0x-x-x-x0
请求中是否有我可以提供的
api_-key
。像用户名和密码一样获取


headers
headers={'Content-type':'application/json','X-IG-API-KEY':'0x-X-X-x0'}中的示例

这就是您要找的吗

import requests
import json
def test_request_response():
    # Send a request to the API server and store the response.
    data = { 'username' : 'sxxxt@xxx.com', 'password' : 'xxxxe' }
    headers = {'Content-type': 'application/json'}
    response = requests.get('https://xx.xxx.com/xx/xx',headers=headers,data=json.dumps(data))
    return response

test_request_response()
参考资料:

您正在尝试这样做吗?
from requests.auth import HTTPBasicAuth
import requests

url = "https://api_url"
headers = {"Accept": "application/json"}
auth = HTTPBasicAuth('apikey', '1234abcd')
files = {'filename': open('filename','rb')}

req = requests.get(url, headers=headers , auth=auth , files=files)