我正在尝试通过以下代码连接套接字
try:
# create an INET, STREAMing socket
self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# now connect to the web server on port 80 - the normal http port
self.client.connect((host, port))
user = ['User.loginByToken', access_token]
self.client.sendall(user)
# self.client._locust_environment = self.environment
except Exception as e:
color_print("\n[!] Check Server Address or Port", color="red", underline=True)
它将引发错误memoryview: a bytes-like object is required, not 'list'
。我该怎么解决?
最佳答案
您需要将用户var转换为字节才能通过套接字发送:
您可以尝试以下方法:
import json
user = json.dumps({'User.loginByToken': access_token})
user = user.encode("utf-8")
关于python-3.x - Python抛出错误字节,如对象要求未列出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65139790/