Python 抛出错误字节,如需要的对象未列出
Python throw error byte like object required not list
我正在尝试通过以下代码连接套接字
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")
我正在尝试通过以下代码连接套接字
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")