简体   繁体   中英

How do I get the url to an api knowing the request url and headers

I wanted to view the raw api data by just typing the url into my browser but I'm not sure how to format the url. Is there a way I can use my python request to get the url I need with the headers included in it?

For example when i type in the request.url: https://free-geo-ip.p.rapidapi.com/json/[my_ip]

I get the error: {"message":"Missing RapidAPI application key. Go to https:\/\/docs.rapidapi.com\/docs\/keys to learn how to get your API application key."}

I have my api key and host which are the headers, I just don't know how to put them in the url.

Here's my python code with my ip address and api key taken out:

import requests

url = "https://free-geo-ip.p.rapidapi.com/json/(my ip address)"

headers = {
    'x-rapidapi-host': "free-geo-ip.p.rapidapi.com",
    'x-rapidapi-key': "(my api key)"
    }

response = requests.request("GET", url, headers=headers)

r = response.json

In Google Chrome, you can use this extension to modify headers: https://chrome.google.com/webstore/detail/modheader/idgpnmonknjnojddfkpgkljpfnnfcklj?hl=en

I ended up using postman to call apis without code.

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