im working on a python code but im getting an error here is my code class Plugin:…
- User
im working on a python code but im getting an error here is my code class Plugin: PIPE_PATH = "/tmp/NSLGameScanner_pipe"
async def read_pipe(self, ws): if not os.path.exists(self.PIPE_PATH): print(f"Pipe file {self.PIPE_PATH} not found") return pipe_fd = os.open(self.PIPE_PATH, os.O_RDONLY | os.O_NONBLOCK) while True: try: line = os.read(pipe_fd, 1024) except BlockingIOError: await asyncio.sleep(0.1) # No data, sleep and try again else: if line: line = line.decode().strip() print(f"Read from pipe: {line}") # print to console await ws.send_str(line) # send to WebSocket client else: break # End of file os.close(pipe_fd) async def websocket_handler(self, request): ws = web.WebSocketResponse() logging.info(f"Preparing WebSocket with request: {request}") try: await ws.prepare(request) except Exception as e: logging.error(f"Failed to prepare WebSocket: {e}") raise # Reraise the exception to handle it in the caller code if not os.path.exists(self.PIPE_PATH): logging.warning(f"Pipe file {self.PIPE_PATH} not found") return ws await self.read_pipe(ws) return ws # Asyncio-compatible long-running code, executed in a task when the plugin is loaded async def _main(self): decky_plugin.logger.info("Hello World!") async def _unload(self): decky_plugin.logger.info("Goodbye World!") if self.site: await self.site.stop() decky_plugin.logger.info("Server stopped") # Log server stop await self.runner.cleanup() decky_plugin.logger.info("Server cleanup completed") # Log server cleanup # Migrations that should be performed before entering `_main()`. async def _migration(self): decky_plugin.logger.info("Migrating") # Initialize the web application and set up the WebSocket route self.app = web.Application() self.app.router.add_route('GET', '/ws', self.websocket_handler) self.runner = web.AppRunner(self.app) self.site = None # Set the command to run your bash script command = "/bin/bash -c 'curl -Ls https://raw.githubusercontent.com/moraroy/NonSteamLaunchers-On-Steam-Deck/main/NonSteamLaunchers.sh | nohup /bin/bash -s -- \"Decky Plugin\"'" # Log the command for debugging decky_plugin.logger.info(f"Running command: {command}") # Set up the environment for the new process env = os.environ.copy() env['DISPLAY'] = ':0' env['XAUTHORITY'] = os.path.join(os.environ['HOME'], '.Xauthority') process = subprocess.Popen(command, shell=True, env=env) # Wait for the script to complete and get the exit code exit_code = process.wait() # Log the exit code for debugging decky_plugin.logger.info(f"Command exit code: {exit_code}") if exit_code == 0: decky_plugin.logger.info("Migration successful") else: decky_plugin.logger.error("Migration failed") # Start the web server and pipe related code here decky_plugin.logger.info("Hello World!") await self.runner.setup() decky_plugin.logger.info("Server setup completed") # Log server setup self.site = web.TCPSite(self.runner, 'localhost', 8765) await self.site.start() decky_plugin.logger.info("Server started") # Log server start - Assistant
There doesn't seem to be any syntax errors in your code. However, you need to import the necessary modules in order to use functions and objects from them. Make sure to add the following import statements at the beginning of your code:
import asyncio import logging import os import subprocess from aiohttp import webAdditionally, make sure that you have the
aiohttppackage installed. You can install it by runningpip install aiohttpin your terminal.If you're still encountering an error, please provide more details about the error message you're getting.
- User
here is the error [2024-02-14 22:55:32,888][ERROR]: Error handling request Traceback (most recent call last): File "aiohttp/web_protocol.py", line 452, in _handle_request File "aiohttp/web_app.py", line 543, in _handle TypeError: Plugin.websocket_handler() missing 1 required positional argument: 'request' [2024-02-14 22:55:32,889][INFO]: ::1 [14/Feb/2024:22:55:32 -0800] "GET /ws HTTP/1.1" 500 245 "-" "Mozilla/5.0 (X11; Linux x86_64; Valve Steam Client/default/1705108172) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" [2024-02-14 22:55:38,217][INFO]: install was called [2024-02-14 22:55:38,217][INFO]: selected_options: {'epicGames': False, 'gogGalaxy': False, 'origin': False, 'uplay': False, 'battleNet': False, 'amazonGames': False, 'eaApp': False, 'legacyGames': False, 'itchIo': False, 'humbleGames': False, 'indieGala': False, 'rockstar': False, 'glyph': False, 'minecraft': False, 'psPlus': False, 'dmm': False, 'xboxGamePass': True, 'geforceNow': False, 'amazonLuna': False, 'netflix': False, 'hulu': False, 'disneyPlus': False, 'amazonPrimeVideo': False, 'youtube': False, 'twitch': False} [2024-02-14 22:55:38,217][INFO]: custom_websites: [] [2024-02-14 22:55:38,217][INFO]: separate_app_ids: False [2024-02-14 22:55:38,218][INFO]: start_fresh: False [2024-02-14 22:55:38,218][INFO]: stop_game_scanner: False [2024-02-14 22:55:38,218][INFO]: selected_options_list: ['"Xbox Game Pass"'] [2024-02-14 22:55:38,220][INFO]: Running command: /bin/bash -c 'curl -Ls | nohup /bin/bash -s -- "Xbox Game Pass"'
- Assistant
The error message indicates that the
Plugin.websocket_handlermethod is missing a required positional argumentrequest. This means that when this method is called, it expects to receive arequestobject as an argument.To fix this issue, you need to update the
websocket_handlermethod signature to include therequestargument. Below is the updated code:async def websocket_handler(self, request): ws = web.WebSocketResponse() logging.info(f"Preparing WebSocket with request: {request}") try: await ws.prepare(request) except Exception as e: logging.error(f"Failed to prepare WebSocket: {e}") raise # Reraise the exception to handle it in the caller code if not os.path.exists(self.PIPE_PATH): logging.warning(f"Pipe file {self.PIPE_PATH} not found") return ws await self.read_pipe(ws) return wsMake sure to replace the existing
websocket_handlermethod with this updated version. This should resolve the error you're encountering. - User
arent i already doing that? is it becuase its its own async definitoon when it needs to be paired with whats going on under migartion method?
- Assistant
Apologies for the confusion. Looking at your code again, it seems that the
websocket_handlermethod is already defined correctly and it is not the source of the error.The error message suggests that the
websocket_handlermethod is being called without providing therequestargument. The error occurs at this line:await ws.prepare(request).Based on the error message and the code you provided, it seems that the
websocket_handlermethod is being called somewhere else in your code without passing therequestargument. You need to locate where this call is happening and make sure to provide therequestargument.If you're not sure where the call to
websocket_handleris being made, you can try adding a print statement at the beginning of the method to see if it's being executed. Additionally, check your code for any other places where you're calling this method and ensure that therequestargument is being passed correctly.