【发布时间】:2021-09-24 14:08:36
【问题描述】:
问题
我正在使用 Python 自动执行 putty 会话。我正在使用 PyAutoGui 加载我保存的会话。当我手动打开腻子,然后运行脚本时,脚本运行良好。但是,当我将 Popen(putty.exe) 添加到我的代码中时,我收到以下错误。我不确定为什么当我手动打开腻子而不是在脚本中打开它时,locateOnScreen 会起作用。我尝试使用打印屏幕和pyautoguis截图功能代替sn-p工具,但没有奏效。
错误
Traceback (most recent call last):
File "C:\filepath\main.py", line 14, in <module>
session_center = pyautogui.center(saved_session)
File "C:\filepath\site-packages\pyscreeze\__init__.py", line 582, in center
return Point(coords[0] + int(coords[2] / 2), coords[1] + int(coords[3] / 2))
TypeError: 'NoneType' object is not subscriptable
代码
import pyautogui
import os
from subprocess import Popen
home = os.path.expanduser('~')
corrected_path = home.replace(os.sep, '\\')
log_path = corrected_path + '\\PyAutoGuiPNGs\\'
Popen('putty.exe')
saved_session = pyautogui.locateOnScreen('saved_session.png', grayscale=True, confidence=.5)
session_center = pyautogui.center(saved_session)
pyautogui.moveTo(session_center)
pyautogui.PAUSE = 1
pyautogui.click()
pyautogui.write('router')
load = pyautogui.locateOnScreen('load.png', grayscale=True, confidence=.5)
load_center = pyautogui.center(load)
pyautogui.moveTo(load_center)
pyautogui.PAUSE = 1
pyautogui.click()
open_button = pyautogui.locateOnScreen('open.png', grayscale=True, confidence=.5)
open_center = pyautogui.center(open_button)
pyautogui.moveTo(open_center)
pyautogui.PAUSE = 1
pyautogui.click()
【问题讨论】: