im working ona decky plugin but getting a Plugin.websockethandler missing 1 required…
- User
im working ona decky plugin but getting a Plugin.websocket_handler missing 1 required positional argument 'request' error here is my code #!/usr/bin/env python3 import os import logging import sys import subprocess import re import asyncio import decky_plugin import aiohttp from aiohttp import web from decky_plugin import DECKY_PLUGIN_DIR
Set up logging
logging.basicConfig(level=logging.DEBUG)
def camel_to_title(s): # Split the string into words using a regular expression words = re.findall(r'[A-Z]?[a-z]+|[A-Z]+(?=[A-Z]|$)', s) # Convert the first character of each word to uppercase and join the words with spaces return ' '.join(word.capitalize() for word in words)
class Plugin: PIPE_PATH = "/tmp/NSLGameScanner_pipe"
code - Assistant
The error you're encountering is because the
websocket_handlermethod is missing therequestargument. You can modify the method signature to include therequestargument as follows:pythonasync def websocket_handler(self, request): ...After making this change, the error should be resolved.
- User
arent i already doing that?
- Assistant
Apologies for the confusion. You're correct, the
websocket_handlermethod already includes therequestargument. The error message you're seeing might occur if you're calling thewebsocket_handlermethod without passing therequestargument.Here's an example of how you can call the
websocket_handlermethod:pythonasync def some_method(self): request = ... # Create the request object await self.websocket_handler(request)Make sure that you're passing the
requestargument properly when calling thewebsocket_handlermethod. If you're still experiencing the error, please provide the specific line of code where thewebsocket_handlermethod is being called so I can assist you further. - User
is it because the pipe oesnt exist? async def websocket_handler(self, request): ws = web.WebSocketResponse() await ws.prepare(request)
codeif not os.path.exists(self.PIPE_PATH): print(f"Pipe file {self.PIPE_PATH} not found") return ws await self.read_pipe(ws) return ws - Assistant
The code you provided suggests that if the pipe file specified by
self.PIPE_PATHdoes not exist, the method will print a message indicating that the file was not found and then return thewsobject without further processing.If the pipe file is missing, calling
ws.prepare(request)could potentially raise an exception because the WebSocket connection may require specific information from the request. If that's the case, you might need to handle it accordingly.To troubleshoot this issue, you can modify the code and add logging statements to track the execution flow and identify the origin of the error:
python