首页 > 解决方案 > 字节中的语法错误(" ".format(), encoding="utf-8")

问题描述

运行时:

import hashlib

hash1 = hashlib.md5(b'admin:Pentester Academy:asdds').hexdigest()
hash2 = hashlib.md5(b'GET:/lab/webapp/digest/1').hexdigest()
nonce = "526f295f84bcafc67598cd8e760a9cc5"

response_unhashed = (bytes("{}:{}:{}".format(hash1, nonce, hash2)), encoding='utf-8')
response_md5hashed = hashlib.md5(response_unhashed).hexdigest()

print(response_md5hashed)

我明白这个...

   Traceback (most recent call last):
  File "C:\Users\Adrian\Desktop\Infosec\Notes\Programming\example.py", line 7
    response_unhashed = (bytes("{}:{}:{}".format(hash1, nonce, hash2)), encoding='utf-8')
                                                         ^
SyntaxError: invalid syntax

语法错误在哪里?检查了一些 bytes() 和 format() 文档,但找不到任何线索。

标签: pythonsyntaxpython-3.8

解决方案


你可以试试这个:

import hashlib
hash1 = hashlib.md5(b'admin:Pentester Academy:asdds').hexdigest()
hash2 = hashlib.md5(b'GET:/lab/webapp/digest/1').hexdigest()
nonce = "526f295f84bcafc67598cd8e760a9cc5"

response_unhashed = bytes("{}:{}:{}".format(hash1,nonce,hash2), encoding = "utf-8")
response_md5hashed = hashlib.md5(response_unhashed).hexdigest()

print(response_md5hashed)

推荐阅读