问题描述
我正在为域可用性检查器编写代码,当我运行代码时,它给了我一个错误,所以我希望有人知道它的解决方案,因为它是一个编码夏令营项目,我应该在这几天内提交它。
代码:
import argparse
import time
import requests
praser = argparse.ArgumentParser(description="Check domain for availability")
praser.add_argument("domain",type=str,help="Domain name to be checked")
args = praser.parse_args()
api_key = "API_KEY"
api_secret = "API_SECRET"
req_headers = {
"Authorization": f"sso-key {api_key}:{api_secret}","Accept": "application/json"
}
def get_req_url(check_domain):
return f"https://api.ote-godaddy.com/v1/domains/available?domain={check_domain}"
def check_domain_availability(check_domain):
print(f"Checking the availability of the domain {check_domain} ...")
req_url = get_req_url(check_domain)
req = requests.get(req_url,headers=req_headers)
if req.status_code != 200:
print(f"Couldn't get availability state of the domain {check_domain} - Status code {req.status_code}")
return
response = req.json()
if response["Available"] == True:
print(f"Domain {check_domain} is available for purchase")
else:
print(f"{time.strftime('%y-%m-D %H:%M')} - Domain {check_domain} is not available for purchase")
check_domain_availability(args.domain)
错误:
用法:godaddy bot.py [-h] 域
Godaddy bot.py:错误:需要以下参数:域
解决方法
您不应在 Python 脚本文件名中使用空格。将您的文件重命名为 godaddy_bot.py
而不是 godaddy bot.py
。
然后运行 python godaddy_bot.py somedomain.com
- 错误消息清楚地告诉您需要将域作为参数提供。