Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:uuu init_uuu()缺少2个必需的位置参数:';客户机接口';和';状态消息';_Python - Fatal编程技术网

Python TypeError:uuu init_uuu()缺少2个必需的位置参数:';客户机接口';和';状态消息';

Python TypeError:uuu init_uuu()缺少2个必需的位置参数:';客户机接口';和';状态消息';,python,Python,我得到以下错误: import socket import sys class SimpleClient: def __init__(self, client_socket, statusMessage): self.client_socket = client_socket self.statusMessage = statusMessage def connectToServer(self): self.client_soc

我得到以下错误:

import socket
import sys

class SimpleClient:
    def __init__(self, client_socket, statusMessage):
        self.client_socket = client_socket
        self.statusMessage = statusMessage

    def connectToServer(self):
        self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        host  = 'cs5700sp15.ccs.neu.edu'
        port  = 27993

        remote_ip = socket.gethostbyname(host)

        try:
            self.client_socket.connect((remote_ip, port))
        except socket.error:
            print ('Connection failed')
            sys.exit()

        print ('Connection successful')

    def sendHelloMessage(self):
        """This funtion sends the initial HELLO message to the server"""
        nu_id = input('Enter your NUID: ')
        hello_message = 'cs5700spring2015 HELLO {}\n'.format(nu_id)
        self.client_socket.send(bytes(hello_message, 'ascii'))

    def receiveStatusMessage(self):
        """This function receives the STATUS message from the server"""
        self.statusMessage = str(self.client_socket.recv(1024))
        print (self.statusMessage)

        #handleStatusMessage()

def main():
  client = SimpleClient()
  client.connectToServer()
  client.sendHelloMessage()
  client.receiveStatusMessage()  

if __name__ == "__main__":main()
回溯(最近一次呼叫最后一次):
文件“/Users/sanketdeshpande/Documents/workspace/test/project01 simpleclient.py”,第49行,在
如果uuuu name_uuuuuu==“uuuuuuu main_uuuuuuuu”:main()
文件“/Users/sanketdeshpande/Documents/workspace/test/project01 simpleclient.py”,第44行,主视图
client=SimpleClient()
TypeError:\uuuuu init\uuuuuuuuuu()缺少2个必需的位置参数:“客户端\u套接字”和“状态消息”

如果希望不允许向类启动器传递任何参数,则必须使用默认值设置为
None
(或任何适当的值)来定义启动器

比如说,

Traceback (most recent call last):
  File "/Users/sanketdeshpande/Documents/workspace/test/project01-simpleclient.py", line 49, in <module>
    if __name__ == "__main__":main()
  File "/Users/sanketdeshpande/Documents/workspace/test/project01-simpleclient.py", line 44, in main
    client = SimpleClient()
TypeError: __init__() missing 2 required positional arguments: 'client_socket' and 'statusMessage'
现在可以调用类实例化,而无需传递初始化参数

def __init__(self, client_socket=None, statusMessage=""):
    self.client_socket = client_socket
    self.statusMessage = statusMessage
你的类接受两个参数,但当你调用它时

class SimpleClient:
    def __init__(self, client_socket, statusMessage):

你没有写任何论点。因此,您必须输入两个参数,它们可能是
None

它需要两个参数(client\u socket,statusMessage),您什么也不给它……此外,您的问题与socket无关,而与基本的Python使用有关。在发布之前,你应该把你的问题减少到一个最小的例子。
class SimpleClient:
    def __init__(self, client_socket, statusMessage):
client = SimpleClient()