im working on my main.py here is my code but ill show the log after #!/usr/bin/env…
- User
im working on my main.py here is my code but ill show the log after #!/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: async def websocket_handler(self, request): ws = web.WebSocketResponse() await ws.prepare(request)
codeasync for msg in ws: if msg.type == web.WSMsgType.TEXT: await ws.send_str("Server received: " + msg.data) elif msg.type == web.WSMsgType.ERROR: print('ws connection closed with exception %s' % ws.exception()) print('websocket connection closed') return ws 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
The code you provided seems incomplete, as there is a missing part after the last commented line. However, I can see that you are working on a Python script named "main.py" that involves importing different modules and defining a class called "Plugin". This class includes methods for handling WebSocket connections and performing migrations.
The script sets up logging using the
logging.basicConfig()function and defines a helper function called "camel_to_title()" for converting camel case strings to title case. The "Plugin" class has a "websocket_handler()" method that handles incoming WebSocket messages and sends a response back to the client. There is also an "_unload()" method that is called when the script is unloaded and performs necessary cleanup tasks.The "_migration()" method initializes a web application and sets up a WebSocket route. It then runs a bash script using subprocess.Popen(), waits for the script to complete, and logs the exit code. After that, it starts a web server on localhost port 8765 and logs the server's start.
Unfortunately, without more context or the missing code, it's challenging to provide further assistance or understand the full functionality of the script.
- User
its getting an error [2024-02-15 03:21:34,351][INFO]: Migrating [2024-02-15 03:21:34,353][INFO]: Running command: /bin/bash -c 'curl -Ls https://raw.githubusercontent.com/moraroy/NonSteamLaunchers-On-Steam-Deck/main/NonSteamLaunchers.sh | nohup /bin/bash -s -- "Decky Plugin"' [2024-02-15 03:21:38,475][INFO]: Command exit code: 0 [2024-02-15 03:21:38,475][INFO]: Migration successful [2024-02-15 03:21:38,475][INFO]: Hello World! [2024-02-15 03:21:38,476][INFO]: Server setup completed [2024-02-15 03:21:38,482][INFO]: Server started [2024-02-15 03:22:38,299][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-15 03:22:38,301][INFO]: ::1 [15/Feb/2024:03:22:38 -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"
- Assistant
The error message indicates that the
websocket_handler()method in thePluginclass is missing a required positional argument:request. This argument is necessary for the method to handle incoming WebSocket requests.To fix this issue, you need to make sure that the
websocket_handler()method accepts therequestargument. You can modify the method definition as follows:pythonasync def websocket_handler(self, request): ...Make sure to update all references to this method and ensure that it is called with the required
requestargument.