我有一个小的应用程序,可以将命令发送到AWS EC2,并在其上运行代码。使用python 3.6在Xubuntu VM上创建了应用程序。在Windows上一切正常。我还设法在此VM上使用Kivy和KivyMD构建了其他应用程序。使用下面的代码和依赖项时,我的应用程序构建成功,但是当我单击智能手机上的图标时,它崩溃了。
这是我的规格文件的一部分。
source.include_exts = py,png,jpg,kv,atlas
requirements = kivy==1.11.1, kivymd, boto3, botocore, openssl, paramiko, urllib3, s3transfer, ecdsa
android.permissions = INTERNET,ACCESS_NETWORK_STATE
我的代码:
from kivy.lang import Builder
from kivymd.app import MDApp
import kivy
import boto3
import paramiko
import io
kivy.require('1.11.1')
KV = '''
Screen:
MDRoundFlatIconButton:
id: button
text: "Start"
font_size: "18sp"
pos_hint: {"center_x": 0.5, "center_y": 0.15}
on_release: app.start()
'''
class MainApp(MDApp):
def build(self):
return Builder.load_string(KV)
def start(self):
def lambda_handler():
client = boto3.client('ec2', aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_key,
region_name='us-east-2')
describeInstance = client.describe_instances()
private_key_file = io.StringIO()
private_key_file.write('key')
private_key_file.seek(0)
# reading pem file and creating key object
key = paramiko.RSAKey.from_private_key(private_key_file)
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname="18.18.18.18", username="ubuntu", pkey=key)
commands = [
"python3 /home/ubuntu/server.py 'text'",
]
print("Starting execution")
for command in commands:
print("Executing command: " + command)
stdin, stdout, stderr = ssh_client.exec_command(command)
print(stdout.read())
print(stderr.read())
print("finished execution")
lambda_handler()
MainApp().run()
如果您在函数中重新安排import boto3 import paramiko
的时间,一切都会开始,但是如果您单击调用涉及这些导入的函数的按钮,则应用程序将崩溃