![](/img/trans.png)
[英]Process finished with exit code -1073740791 (0xC0000409) on PyCharm with XGBoost
[英]Process finished with exit code -1073740791 (0xC0000409) PyQt5 and Firebase authentication
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QApplication
from PyQt5.uic import loadUi
import pyrebase
firebaseConfig = {......}
firebase=pyrebase.initialize_app(firebaseConfig)
AUTH = firebase.auth()
class Login(QDialog):
def __init__(self):
super(Login,self).__init__()
loadUi("login.ui",self)
self.login.clicked.connect(self.loginfunction)
self.password.setEchoMode(QtWidgets.QLineEdit.Password)
self.clickhere.clicked.connect(self.gotocreate)
self.invalid.setVisible(False)
def loginfunction(self):
email=self.email.text()
password=self.password.text()
try:
auth.sign_in_with_email_and_password(email,password)
except:
self.invalid.setVisible(True)
def gotocreate(self):
createacc=CreateAcc()
widget.addWidget(createacc)
widget.setCurrentIndex(widget.currentIndex()+1)
class CreateAcc(QDialog):
def __init__(self):
super(CreateAcc,self).__init__()
loadUi("createacc.ui",self)
self.confirmacc.clicked.connect(self.createaccfunction)
self.password.setEchoMode(QtWidgets.QLineEdit.Password)
self.confirmpass.setEchoMode(QtWidgets.QLineEdit.Password)
self.invalid.setVisible(False)
def createaccfunction(self):
email = self.email.text()
if self.password.text()==self.confirmpass.text():
password=self.password.text()
try:
AUTH.create_user_with_email_and_password(email,password)
login = Login()
widget.addWidget(login)
widget.setCurrentIndex(widget.currentIndex() + 1)
except:
self.invalid.setVisible(True)
#------main-------#
app=QApplication(sys.argv)
mainwindow=Login()
widget=QtWidgets.QStackedWidget()
widget.addWidget(mainwindow)
widget.setFixedWidth(480)
widget.setFixedHeight(620)
widget.show()
app.exec_()
使用此代碼,我試圖將從用戶收到的信息保存到 Firebase 數據庫,但我不斷收到“進程完成,退出代碼 -1073740791 (0xC0000409)”錯誤。 我決定使用異常處理,但這次“try:”塊不起作用。 也許我不應該使用身份驗證方法來注冊用戶。 有什么建議嗎?
所以這是.ui文件
注冊屏幕ui文件在下面
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>620</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(54, 54, 54);</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>180</x>
<y>50</y>
<width>181</width>
<height>61</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 28pt "MS Shell Dlg 2"; color: rgb(243, 243, 243)</string>
</property>
<property name="text">
<string>Sign up</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>40</x>
<y>170</y>
<width>141</width>
<height>61</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 15pt "MS Shell Dlg 2";
color: rgb(255, 0, 127);</string>
</property>
<property name="text">
<string>Email</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>40</x>
<y>270</y>
<width>141</width>
<height>61</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 15pt "MS Shell Dlg 2";
color: rgb(255, 0, 127);</string>
</property>
<property name="text">
<string>Password</string>
</property>
</widget>
<widget class="QLineEdit" name="email">
<property name="geometry">
<rect>
<x>220</x>
<y>180</y>
<width>211</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="password">
<property name="geometry">
<rect>
<x>220</x>
<y>280</y>
<width>211</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="confirmacc">
<property name="geometry">
<rect>
<x>300</x>
<y>450</y>
<width>141</width>
<height>41</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color:rgb(167, 168, 167); font-size:14px</string>
</property>
<property name="text">
<string>Confirm</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>40</x>
<y>360</y>
<width>171</width>
<height>61</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 15pt "MS Shell Dlg 2";
color: rgb(255, 0, 127);</string>
</property>
<property name="text">
<string>Confirm Pass</string>
</property>
</widget>
<widget class="QLineEdit" name="confirmpass">
<property name="geometry">
<rect>
<x>220</x>
<y>370</y>
<width>211</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="invalid">
<property name="geometry">
<rect>
<x>310</x>
<y>420</y>
<width>131</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 0, 0)</string>
</property>
<property name="text">
<string>Invalid Email</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
登錄屏幕 ui 在下面
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>620</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(54, 54, 54);</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>180</x>
<y>50</y>
<width>131</width>
<height>61</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 28pt "MS Shell Dlg 2"; color: rgb(243, 243, 243)</string>
</property>
<property name="text">
<string>Login </string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>40</x>
<y>170</y>
<width>141</width>
<height>61</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 15pt "MS Shell Dlg 2";
color: rgb(255, 0, 127);</string>
</property>
<property name="text">
<string>Username</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>40</x>
<y>270</y>
<width>141</width>
<height>61</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 15pt "MS Shell Dlg 2";
color: rgb(255, 0, 127);</string>
</property>
<property name="text">
<string>Password</string>
</property>
</widget>
<widget class="QLineEdit" name="email">
<property name="geometry">
<rect>
<x>200</x>
<y>180</y>
<width>201</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="password">
<property name="geometry">
<rect>
<x>200</x>
<y>280</y>
<width>201</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="login">
<property name="geometry">
<rect>
<x>300</x>
<y>430</y>
<width>141</width>
<height>41</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color:rgb(167, 168, 167); font-size:14px</string>
</property>
<property name="text">
<string>Login</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>200</x>
<y>350</y>
<width>161</width>
<height>16</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">color:rgb(255, 255, 255)</string>
</property>
<property name="text">
<string>Don't have an account? </string>
</property>
</widget>
<widget class="QPushButton" name="clickhere">
<property name="geometry">
<rect>
<x>340</x>
<y>350</y>
<width>91</width>
<height>21</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color:#363636; font-size:14px; color: rgb(230, 230, 230)</string>
</property>
<property name="text">
<string>Click here!</string>
</property>
</widget>
<widget class="QLabel" name="invalid">
<property name="geometry">
<rect>
<x>310</x>
<y>400</y>
<width>121</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 0, 0)</string>
</property>
<property name="text">
<string>Invalid Login</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
如果您想知道錯誤的原因,那么您應該在控制台中運行腳本以獲得更具描述性的消息而不是數字代碼。
我看到邏輯很混亂,在這種情況下,我更喜歡 class 只處理身份驗證或用戶創建的邏輯:
from functools import cached_property
import threading
import sys
from PyQt5.QtCore import QObject, pyqtSignal
from PyQt5.QtWidgets import QDialog, QApplication, QStackedWidget, QLineEdit
from PyQt5.uic import loadUi
import pyrebase
class Reply(QObject):
finished = pyqtSignal(object, str)
def execute(self, *args, **kwargs):
threading.Thread(target=self._execute, args=(args, kwargs), daemon=True).start()
def _execute(self, args, kwargs):
error = ""
result = None
try:
result = self.task(*args, **kwargs)
except Exception as e:
error = str(e)
self.finished.emit(result, error)
def task(self, *args, **kwargs):
pass
class SignInReply(Reply):
def task(self, auth, email, password):
return auth.sign_in_with_email_and_password(email, password)
class CreateUserReply(Reply):
def task(self, auth, email, password):
return auth.create_user_with_email_and_password(email, password)
class LoginWidget(QDialog):
def __init__(self):
super(LoginWidget, self).__init__()
loadUi("login.ui", self)
self.password.setEchoMode(QLineEdit.Password)
self.invalid.setVisible(False)
def credentials(self):
return self.email.text(), self.password.text()
def update_status(self, status):
if not status:
self.invalid.show()
class CreateAcc(QDialog):
def __init__(self):
super(CreateAcc, self).__init__()
loadUi("createacc.ui", self)
self.password.setEchoMode(QLineEdit.Password)
self.confirmpass.setEchoMode(QLineEdit.Password)
self.invalid.hide()
def credentials(self):
return self.email.text(), self.password.text(), self.confirmpass.text()
def update_status(self, status):
if not status:
self.invalid.show()
class Manager(QObject):
def __init__(self, parent=None):
super().__init__(parent)
self.stacked_widget.addWidget(self.login_widget)
self.stacked_widget.addWidget(self.create_account_widget)
self.stacked_widget.setFixedSize(480, 620)
self.login_widget.login.clicked.connect(self.login)
self.login_widget.clickhere.clicked.connect(self.open_create_widget)
self.create_account_widget.confirmacc.clicked.connect(self.create_user)
@cached_property
def firebase(self):
config = {}
return pyrebase.initialize_app(config)
@cached_property
def auth(self):
return self.firebase.auth()
@cached_property
def stacked_widget(self):
return QStackedWidget()
@cached_property
def login_widget(self):
return LoginWidget()
@cached_property
def create_account_widget(self):
return CreateAcc()
def login(self):
email, password = self.login_widget.credentials()
reply = SignInReply(self)
reply.finished.connect(self.handle_signin)
reply.execute(self.auth, email, password)
def create_user(self):
email, password, confirm_password = self.create_account_widget.credentials()
if password == confirm_password:
reply = CreateUserReply(self)
reply.finished.connect(self.handle_create_user)
reply.execute(self.auth, email, password)
else:
self.create_account_widget.update_status(False)
def handle_signin(self, user, error):
self.login_widget.update_status(not error or user)
def handle_create_user(self, result, error):
if not error:
self.stacked_widget.setCurrentWidget(self.login_widget)
def open_create_widget(self):
self.stacked_widget.setCurrentWidget(self.create_account_widget)
if __name__ == "__main__":
app = QApplication(sys.argv)
manager = Manager()
manager.stacked_widget.show()
app.exec_()
注意:請求正在第二個線程中執行,因為這些任務可能需要很長時間才能阻塞 GUI。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.