I’m having an API pull an ID then use that ID to finish a URL for an API request.
def get_id(hostname, headers, verbose): id_query = {'name': hostname} id_response = requests.get(url = "/api/", headers = headers, verify = False, timeout=120, params=id_query) id_status = id_response.status_code id_payload = id_response.json() id = id_payload["results"][0]["id"] print(id) return id url = f"url.com/api/client/{id}"
When the URL is tried in my API request I get an HTTP 404 error, when I print url I get a (id,) added to the end of the URL instead of just the ID. Example if I had the ID as 1
url.com/api/client/(1,)
When I print just the variable, print(id)
I get just the number value, no added (number,). What is going on here? I also tried using .format()
with no change.
Advertisement
Answer
The url
parameter in the requests.get
call is probably incorrect – an API endpoint rarely ends in a forward slash.