2

I'm trying to automate a task using pyautogui in windows built on the Azure cloud. But when I disconnect the remote connection, the pyautogui process does not work. My code↓

import time
import pyautogui as pg

pg.hotkey('alt', 'tab')    #This line and
for i in range(10):
    pg.press(str(i))       #The processing of this line will not be executed.
    time.sleep(1)

Is there any way to run pyautogui without a remote connection?

■Environment

Azure VM windows 10 python 3.9.7 PyAutoGUI 0.9.53

■Detail operation is below.

 1. Run the my program on the cloud machine.

 2. Disconnects the cloud machine while the program is running.

 3. Reconnect and check the program's result.

 4. Error log is below.

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.

But I tried [pg.FAILSAFE = True]. There is no error but results are not normal behavior.

yuu Iri
  • 17
  • 4

2 Answers2

0

You have to run the program on the cloud. I guess you run it on your local machine, right?

Update: Add logging to your code like below:

import logging
logging.basicConfig(filename='logs.log', level=logging.DEBUG, format="%(asctime)s:%(levelname)s: %(message)s")
logging.getLogger().addHandler(logging.StreamHandler())

Now you can find the problem.

Nima
  • 404
  • 3
  • 14
  • The program is running on a cloud machine. – yuu Iri Sep 20 '21 at 06:26
  • So you need to provide more details. Any error occurred? Add logging to your script and check the logs. – Nima Sep 20 '21 at 06:41
  • I edited my question to describe details. Unfortunately, there is no error log in the file. So I described stdout's log. – yuu Iri Sep 20 '21 at 07:19
  • That's it! When you disconnect, the mouse moves to a corner and causes the error. This is the problem. The solution? Unfortunately, I don't know. I don't know how the Azure cloud works. Something I can suggest is to put the mouse in the middle of the screen before disconnecting, and don't move it until completely disconnected. – Nima Sep 20 '21 at 07:31
  • Thank you for your consideration. I think this is a difficult problem for all RPA engineers. Thank you advice for me! – yuu Iri Sep 20 '21 at 11:15
0

Maybe you have to run programm in the background, so it doesn't stop when you close the connection or the terminal.

Some websites like this could help you.

lennart
  • 88
  • 6