我有一个简单的程序,要求用户登录,然后ldap检查其凭据,然后继续该程序。但是,一旦我添加了ldap并将其编译到.exe中,任何成功的登录都会使程序崩溃。我使用pip install auto-py-to-exe
编译程序,选择的选项是:Onefile,基于窗口,然后命名输出。
import sys, ldap
from sys import platform
if platform == "win32":
import win32gui
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
class LoginForm(QWidget):
def __init__(self, width, height):
super().__init__()
self.setWindowTitle('Login Form')
self.resize(width / 3, height / 3)
layout = QGridLayout()
label_name = QLabel('<font size="4"> Username: </font>')
self.lineEdit_username = QLineEdit()
self.lineEdit_username.setPlaceholderText('Please enter '
'your username')
layout.addWidget(label_name, 0, 0)
layout.addWidget(self.lineEdit_username, 0, 1)
label_password = QLabel('<font size="4"> Password: </font>')
self.lineEdit_password = QLineEdit()
self.lineEdit_password.setPlaceholderText('Please enter '
'your password')
self.lineEdit_password.setEchoMode(QtWidgets.QLineEdit.Password)
layout.addWidget(label_password, 1, 0)
layout.addWidget(self.lineEdit_password, 1, 1)
button_login = QPushButton('Login')
button_login.clicked.connect(self.showApp)
layout.addWidget(button_login, 2, 0, 1, 2)
layout.setRowMinimumHeight(2, 75)
self.setLayout(layout)
def checkPass(self):
if self.lineEdit_username.text() != '' \
and self.lineEdit_password.text() != '':
self.user = self.lineEdit_username.text()
conn = ldap.initialize('ldap://ldap.com')
conn.protocol_version = 3
conn.set_option(ldap.OPT_REFERRALS, 0)
try:
result = conn.simple_bind_s(self.user + "@ldap.com",
self.lineEdit_password
.text())
except ldap.INVALID_CREDENTIALS:
return "Invalid credentials"
except ldap.SERVER_DOWN:
return "Server down"
except ldap.LDAPError as e:
if type(e.message) == dict and e.message.has_key('desc'):
return "Other LDAP error: " + e.message['desc']
else:
return "Other LDAP error: " + e
finally:
conn.unbind_s()
return 'Success'
def showApp(self):
msg = QMessageBox()
result = self.checkPass()
if result == 'Success':
#continue with the program
else:
msg.setText(result)
msg.exec_()
if __name__ == '__main__':
app = QApplication(sys.argv)
screenRes = app.desktop().screenGeometry()
width, height = screenRes.width(), screenRes.height()
form = LoginForm(width, height)
form.show()
if win32gui in sys.modules:
form.setWindowState(Qt.WindowActive)
sys.exit(app.exec_())
我的代码或编译方法是否需要更改?我找不到调试它的好方法。
编辑:我开始屏幕记录调试窗口,以便在崩溃后可以读取它,并说configparser not found in PYZ
我也曾尝试做过--hidden-import=configparser