python-3.x - 在使用 python 库 random_word 制作这个随机密码生成器时,elif 语句中的“随机词”有时会返回“无”
问题描述
import numpy as np
from random_word import RandomWords
r = RandomWords()
promptInput = str(input("Do you want to enter your on prompt or randomly generate it, answer
in yes or no : "))
if promptInput == "yes" :
passwordHint = str(input("Enter a prompt for making the password : "))
nums = np.random.randint(1000, 9999)
newHint = passwordHint.capitalize()
nums = str(nums)
password = newHint + nums
print(password)
elif promptInput == "no" :
randomWord = str(r.get_random_word(minLength = 5,maxLength = 7))
nums = np.random.randint(1000, 9999)
newRandomWord = randomWord.capitalize()
nums = str(nums)
password2 = newRandomWord + nums
print(password2)
打印这主要是返回“无”,然后是随机数,例如 - None8797
else :
print("Enter yes or no only")
这也可能是一个问题,因为我之前想测试代码是否可以工作,所以我在 elif 语句中输入了 print("none")
解决方案
看起来你正在使用这个模块:
如果您查看它的源代码,您会注意到它从 api.wordnik.com 的在线服务中获取随机单词。如果您尝试生成安全密码,这绝对是一个糟糕的主意。
更糟糕的是,该服务仅在提供有效 API 密钥时才会响应。该模块具有三个嵌入式 API 密钥:
---
API_KEY:
- "d146825 .......... (redacted) .......... 92d3230"
- "1eirq2g .......... (redacted) .......... w02zyj7"
- "c23b746 .......... (redacted) .......... b9b658e"
我尝试使用其中之一,并得到以下响应:
{"message":"API rate limit exceeded"}
这可能是导致空响应的原因。我建议您立即停止使用此模块并找到更好的解决方案。
推荐阅读
- java - List 的未经检查的转换警告
- python - Python Pandas 中的排列和组合
- typescript - 从未在类型接口中声明的对象中删除属性
- java - Java making switch case statment shorter
- python - passing a parameter to a form in FormView Django
- c# - 在文件夹视图中,Visual Studio 2017 中的项目属性在哪里?
- azure-application-insights - Azure Application Insights 中的用户代理信息
- c++ - 执行顺序问题
- regex - 在 bash 脚本中的 case 语句中捕获模式组
- c# - 将弹出分数放置在敌方位置