阿里云实例重启封装成二进制文件

2022-07-14  本文已影响0人  Al_不期而遇

ECS服务器重启

环境Ubuntu 20.04

以下是重启ECS代码

#!/usr/bin/env python
#coding=utf-8

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkecs.request.v20140526.RebootInstanceRequest import RebootInstanceRequest

client = AcsClient('<accessKeyId>', '<accessSecret>', 'cn-hangzhou')

request = RebootInstanceRequest()
request.set_accept_format('json')

request.set_InstanceId("i-bp17axxxx")
request.set_ForceStop(False)
request.set_DryRun(False)

response = client.do_action_with_exception(request)
# python2:  print(response) 
print(str(response, encoding='utf-8'))

生成二进制可执行文件

pip3 install pyinstaller
pyinstaller -F -w --noconfirm reboot_ecs.py 
pyinstaller -F -w --clean --noconfirm reboot_ecs.spec 
在当前目录下有个dist目录
将文件copy对应人就可以了,不需要安装python环境

报错信息

Traceback (most recent call last):
  File "reboot_ecs.py", line 2, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 495, in exec_module
  File "aliyunsdkcore/client.py", line 32, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 495, in exec_module
  File "aliyunsdkcore/vendored/requests/__init__.py", line 54, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 495, in exec_module
  File "aliyunsdkcore/vendored/requests/utils.py", line 23, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 495, in exec_module
  File "aliyunsdkcore/vendored/requests/certs.py", line 17, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 495, in exec_module
  File "aliyunsdkcore/vendored/requests/packages/__init__.py", line 3, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 495, in exec_module
  File "aliyunsdkcore/vendored/requests/packages/urllib3/__init__.py", line 8, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 495, in exec_module
  File "aliyunsdkcore/vendored/requests/packages/urllib3/connectionpool.py", line 28, in <module>
  File "aliyunsdkcore/vendored/requests/packages/urllib3/packages/six.py", line 92, in __get__
  File "aliyunsdkcore/vendored/requests/packages/urllib3/packages/six.py", line 115, in _resolve
  File "aliyunsdkcore/vendored/requests/packages/urllib3/packages/six.py", line 82, in _import_module
ModuleNotFoundError: No module named 'queue'

解决方式 import queue

上一篇下一篇

猜你喜欢

热点阅读