Zend certified PHP/Magento developer

Script to automate mfa when using scp (otp then key) currently using python open to other suggestions

I can’t seem to find any information on how to automate both otp and key login with a script on the client side. My server is set up to require otp then require key. Both client and server are running fedora linux. My previous automated script was python and I’m trying to update it in python. Currently I have this

import subprocess

import pexpect

… # code to find files and make them into a list and defining the command

otp = subprocess.run (‘oathtool –totp -b my_secret_code’, shell=True, stdout=subprocess.PIPE, text=True)

otp = otp.stdout

otp = otp.strip(‘n’)

run = pexpect.spawn(command)

run.expect(‘.*’)

run.sendline(otp)

when I run this the server side accepts the pam authentication but then connection is closed before any file transfer happens. Any suggestions as to why this happens?