【问题标题】:Usage: godaddy bot.py [-h] domain godaddy bot.py: error: the following arguments are required: domain用法:godaddy bot.py [-h] domain godaddy bot.py: 错误:需要以下参数:domain
【发布时间】:2021-03-08 18:33:24
【问题描述】:

我正在为域可用性检查器编写代码,当我运行代码时,它给了我一个错误,所以我希望任何人都知道它的解决方案,因为它是一个编码夏令营项目,我应该在那几天提交它。

代码:

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 argparse godaddy-api


    【解决方案1】:

    您不应该在 Python 脚本文件名中使用空格。将您的文件重命名为 godaddy_bot.py 而不是 godaddy bot.py

    然后运行python godaddy_bot.py somedomain.com - 错误消息清楚地告诉您需要将域作为参数提供给它。

    【讨论】:

    • 如何将域作为参数?对不起,我还是个初学者?
    • 通过在命令行上写下我所说的。如果您通过某个 IDE 或编辑器运行程序,请查阅其说明。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 2022-06-29
    • 2019-09-06
    • 2019-05-26
    • 2014-04-23
    • 1970-01-01
    相关资源
    最近更新 更多