Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyautogui does not work as windows service #869

Open
Humburto opened this issue Aug 2, 2024 · 1 comment
Open

pyautogui does not work as windows service #869

Humburto opened this issue Aug 2, 2024 · 1 comment

Comments

@Humburto
Copy link

Humburto commented Aug 2, 2024

I wrote a simple app with pyautogui and flask as follow. When I request http://{ip}/, the "windows" key should be pressed(so the windows start menu should appear).

import pyautogui
from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    pyautogui.press('win')
    return "hello world"

if __name__ == '__main__':
    app.run(host="0.0.0.0", port="80")

When I run this app in a terminal, it works as expected. However, when I warp it to a windows service with nssm(the non-sucking service manager), it does not work any more.

When I request the url, pyautogui raise some errors about failsafe:

[2024-08-02 22:05:12,577] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "D:\code\media-remote\.venv\Lib\site-packages\flask\app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\code\media-remote\.venv\Lib\site-packages\flask\app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\code\media-remote\.venv\Lib\site-packages\flask\app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\code\media-remote\.venv\Lib\site-packages\flask\app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\code\media-remote\test.py", line 8, in index
    pyautogui.press('win')
  File "D:\code\media-remote\.venv\Lib\site-packages\pyautogui\__init__.py", line 593, in wrapper
    failSafeCheck()
  File "D:\code\media-remote\.venv\Lib\site-packages\pyautogui\__init__.py", line 1734, in failSafeCheck
    raise FailSafeException(
pyautogui.FailSafeException: PyAutoGUI fail-safe triggered from mouse moving to a corner of the screen. To disable this fail-safe, set pyautogui.FAILSAFE to False. DISABLING FAIL-SAFE IS NOT RECOMMENDED.

I tried set pyautogui.FAILSAFE= False to disable failsafe then it did not raise above errors, but the windows start menu also did not appear( which means the windows key was not pressed).

Any help will be appreciated, thanks.

@henygebremedhin
Copy link

henygebremedhin commented Aug 2, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants