Calling REST API with an API key using the requests package in Python

前端 未结 1 1586
青春惊慌失措
青春惊慌失措 2021-01-06 09:41

What should the python code to call the REST API below using the requests package? I do not know how to pass the \"apikey\"

curl -X POST -u \"apikey\":\"123         


        
相关标签:
1条回答
  • 2021-01-06 10:18

    Your curl command is likely to the code. When you do not know what it supports to. You can curl --help or use curl ... --trace-ascii 1.txt to figure out the process

    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)
    
    0 讨论(0)
提交回复
热议问题