I started working, with Alexa RANK API and I would like to use python request to make my API call:
that's what Alexa propose on the website:
curl -H "x-api-key: SMAxxxxxxxxxxxxx8sD2FDtzgaHtGEotx" "https://awis.api.alexa.com/api?Action=UrlInfo&Count=10&ResponseGroup=Rank,LinksInCount&Start=1&Url=cnn.com"
This is my incorrect code:(
from requests.auth import HTTPBasicAuth
import requests
url = "https://awis.api.alexa.com/api?Action=UrlInfo&Count=10&ResponseGroup=Rank,LinksInCount&Start=1&Url=cnn.com"
headers = {"Accept": "application/json"}
auth = HTTPBasicAuth('x-api-key', 'SMADth1Axxxxxxxxxxx8sD2FDtzgaHtGEotx')
Use it all the time. But basically everything after the? is in the payload and then you have to add the headers separately
Also see the requests documentation here https://requests.readthedocs.io/en/master/user/quickstart/#passing-parameters-in-urls
If you use an API Development platform like PostMan , you can use their "code snippets" feature to get the conversions of the API calls in multiple languages including Python.
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.