Python 使用配置文件创建 windows exe 以传递用户名和密码
Python create windows exe with a config file to pass username and password
我有一个 python 脚本用于检查流行的比特币挖矿网站上的再投资设置,我想使用 Pyinstaller 创建一个 windows .exe 文件进行分发。但是,在我传递电子邮件和密码的有效负载部分,用户将无法对其进行编辑。所以我需要能够生成 .exe 和一个配置文件,用户可以在其中编辑他们的电子邮件和密码信息。
我正在使用请求(会话),示例负载是这样的:
payload = {
'action': 'dashboard.php',
'email': 'user@email.com',
'password': 'abc123-pass'
}
我需要将它们更改为变量,并在执行 exe 时从配置文件中读取它们。
只需使用 configparser 或(Python2.7 的 ConfigParser)访问配置文件。
然后你可以创建一个配置文件,如:
# This is the configuration file for my script for user X
[DEFAULT]
action = dashboard.php
email = user@email.com
password = abc123-pass`
在你的脚本中
import configparser
my_config_parser = configparser.SafeConfigParser()
my_config_parser.read('name of your configuration file')
payload = {
'action': my_config_parser.get('DEFAULT','action'),
'email': my_config_parser.get('DEFAULT','email'),
'password': my_config_parser.get('DEFAULT','password')
}
您需要与执行脚本一起发送的配置文件。
您还可以将选项 --exclude-module settings add-data settings.py;.
传递给 PyInstaller。这样 settings.py 将在编译后的应用程序目录中结束,并且可以以通常的方式导入。
我有一个 python 脚本用于检查流行的比特币挖矿网站上的再投资设置,我想使用 Pyinstaller 创建一个 windows .exe 文件进行分发。但是,在我传递电子邮件和密码的有效负载部分,用户将无法对其进行编辑。所以我需要能够生成 .exe 和一个配置文件,用户可以在其中编辑他们的电子邮件和密码信息。
我正在使用请求(会话),示例负载是这样的:
payload = {
'action': 'dashboard.php',
'email': 'user@email.com',
'password': 'abc123-pass'
}
我需要将它们更改为变量,并在执行 exe 时从配置文件中读取它们。
只需使用 configparser 或(Python2.7 的 ConfigParser)访问配置文件。 然后你可以创建一个配置文件,如:
# This is the configuration file for my script for user X
[DEFAULT]
action = dashboard.php
email = user@email.com
password = abc123-pass`
在你的脚本中
import configparser
my_config_parser = configparser.SafeConfigParser()
my_config_parser.read('name of your configuration file')
payload = {
'action': my_config_parser.get('DEFAULT','action'),
'email': my_config_parser.get('DEFAULT','email'),
'password': my_config_parser.get('DEFAULT','password')
}
您需要与执行脚本一起发送的配置文件。
您还可以将选项 --exclude-module settings add-data settings.py;.
传递给 PyInstaller。这样 settings.py 将在编译后的应用程序目录中结束,并且可以以通常的方式导入。