繁体   English   中英

Python 抛出错误字节,如 object 需要未列出

[英]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")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM