AttributeError: 类实例没有属性

我不知道这里的错误是什么


我知道这很乱但是在客户端连接并发送消息后我得到了一个异常


这里的错误ID



Exception in thread Thread-1:

Traceback (most recent call last):

  File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\threading.py", line 810, in __bootstrap_inner

    self.run()

  File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\threading.py", line 763, in run

    self.__target(*self.__args, **self.__kwargs)

  File "C:\Users\Gadi Tepper\PycharmProjects\Connection1\functions.py", line 12, in check_available_message

    user_uid = user.user_uid

AttributeError: Message instance has no attribute 'user_uid'

这是功能


import time


from message import *

from user import *



def check_available_message(messages, users):

    while True:


        for message in messages:

            for user in users:

                user_uid = user.user_uid

                dest_uid = message.receiver_uid

                if user_uid == dest_uid:

                    print("got here")

                    send_message(messages, message, user.user_socket)



def send_message(messages, message, user_socket):

    print(message.sender_uid + " can send a message to: " + message.sender_uid)

    time.sleep(1)

    data = str((message.receiver_uid + "//" + message.sender_uid + "//" + message.data)).encode

    user_socket.send(data)

    messages.remove(message)

这些是对象


class User:

    def __init__(self, user_uid, user_socket):

        self.user_uid = user_uid

        self.user_socket = user_socket


class Message:

    def __init__(self, sender_uid, receiver_uid, data):

        self.sender_uid = sender_uid

        self.receiver_uid = receiver_uid

        self.data = data


动漫人物
浏览 94回答 2
2回答

互换的青春

你在向后传递你的论点。您像这样设置线程:target=check_available_message, args=(users, messages))但是您的方法需要消息作为第一个参数,用户作为第二个参数:def check_available_message(messages, users):

繁星淼淼

您的服务器中的参数顺序错误。在 functions.py 中,你正在接受check_available_message(messages, users),在服务器中你有另一个订单 -args=(users, messages)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python