我的实际代码文件如下:
from autobahn.twisted.websocket import WebSocketClientProtocol,
WebSocketClientFactory, connectWS
from twisted.internet import reactor, ssl
class webSocketOperations(WebSocketClientProtocol):
def kill_connection(self,exit_code=1000,reason=None):
self.sendClose(1000,reason)
def stop_websocket():
class_obj = SomeClass()
class_obj.kill_connection(1000,"normal exit from websocket")
def start_websocket():
url = "wss://someurl"
factory = WebSocketClientFactory(url)
factory.protocol = webSocketOperations
connectWS(factory)
reactor.run()
从中进行呼叫的另一个文件看起来像 假设所有进口都是
start_websocket()
stop_websocket()
当我运行更高版本的文件时,出现的错误是:
AttributeError: 'webSocketOperations' object has no attribute 'state'