Мне нужно авторизоваться в другом python скрипте
Код скрипта, в который необходимо войти
import getpass
import time
time.sleep(1)
login = input('Please enter your login: ')
print('login '+login)
time.sleep(1)
code = input('Please enter the code you received: ')
print('code '+code)
time.sleep(1)
password = getpass.getpass('Please enter your password: ')
print('password '+password)
print('Signed in successfully as '+login)
Код скрипта автоматизации аутентификации
import pexpect
from pexpect import popen_spawn
import time
import sys
login = 'nickname'
code = '12345'
password = 'secret'
command = "python auth.py"
print(command)
child = pexpect.popen_spawn.PopenSpawn(command)
child.logfile = sys.stdout.buffer
#enter login
try:
child.expect('Please enter your login: ')
except pexpect.exceptions.TIMEOUT:
print('Already auth')
sys.exit()
child.sendline(login)
#enter code
child.expect('Please enter the code you received: ')
child.sendline(code)
#enter password
child.expect('Please enter your password: ')
child.sendline(password)
i = child.expect(['Signed in successfully.*',])
if i==0:
print('success Signed')
Вывод сценария автоматизации
python auth.py
Please enter your login: nickname
login nickname
Please enter the code you received: 12345
Please enter your password: Traceback (most recent call last):
File ".\check.py", line 24, in
child.expect('Please enter your password: ')
File "C:\Users\Telnet\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pexpect\spawnbase.py", line 343, in expect
return self.expect_list(compiled_pattern_list,
File "C:\Users\Telnet\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pexpect\spawnbase.py", line 372, in expect_list
return exp.expect_loop(timeout)
File "C:\Users\Telnet\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pexpect\expect.py", line 181, in expect_loop
return self.timeout(e)
File "C:\Users\Telnet\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pexpect\expect.py", line 144, in timeout
raise exc
pexpect.exceptions.TIMEOUT:
searcher: searcher_re:
0: re.compile(b'Please enter your password: ')
searcher: searcher_re:
0: re.compile(b'Please enter your password: ')
Как видно, child.expect ('Пожалуйста, введите ваш пароль:') не работает
Скажите, что я делаю неправильно?