I am trying to write a script to check whether or not a domain is available on GoDaddy. I am getting a 401 error from GoDaddy, meaning there is something wrong with the authorization/API key.
I tried going over the code line by line, following this tutorial: https://www.youtube.com/watch?v=upZfVyGNEfo&t=1s . I was expecting my code to reach the end of the script and print "Checking..." but req.status_code was != 200, so it entered the if statement and terminated.
import requests
domain = "domainmsterrrererere.com"
# godady API credentials for authorization
api_key = "3mM44UdBKEgCgg_LZGKAjFRjjX5DWSDr5asNL"
api_secret = "NxW5aV4YPzicjPKREwgTy7"
req_headers = {
"Authorization": f"sso-key {api_key} : {api_secret}",
"accept": "application/json"
}
# assemble the request url with given domain
def get_req_url(check_domain):
return f"https://api.ote-godaddy.com/v1/domains/available?domain={check_domain}"
def check_domain_available(check_domain):
print(f"Checking avilability of domain {check_domain}")
req_url = get_req_url(check_domain)
req = requests.get(req_url, headers=req_headers)
# if the request was unsuccessul, notify the user and stop
if req.status_code != 200:
print(req.status_code)
return
# check if domain is available
print("Checking...")
check_domain_available(domain)