【问题标题】:Process finished with exit code -1073740791 (0xC0000409) PyQt5 and Firebase authentication进程以退出代码 -1073740791 (0xC0000409) PyQt5 和 Firebase 身份验证完成
【发布时间】:2021-04-03 14:44:58
【问题描述】:
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 &quot;MS Shell Dlg 2&quot;; 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 &quot;MS Shell Dlg 2&quot;;
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 &quot;MS Shell Dlg 2&quot;;
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 &quot;MS Shell Dlg 2&quot;;
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>

登录界面在下方

<?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 &quot;MS Shell Dlg 2&quot;; 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 &quot;MS Shell Dlg 2&quot;;
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 &quot;MS Shell Dlg 2&quot;;
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>

【问题讨论】:

    标签: python firebase pyqt pyqt5 registration


    【解决方案1】:

    如果您想知道错误的原因,那么您应该在控制台中运行脚本以获得更具描述性的消息而不是数字代码。

    我看到逻辑很乱,在这种情况下我更喜欢有一个只处理身份验证或用户创建逻辑的类:

    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。

    【讨论】:

    • “如果您想知道错误的原因,那么您应该在控制台中运行脚本以获得更具描述性的消息而不是数字代码。[...]”。我有类似的失败代码。当我在调试模式 (PyCharm) 下运行它时,如果我单步执行导入语句并让其余代码运行,则不会出现错误。我知道这不是很多信息,但是您知道为什么会发生这种情况吗?
    猜你喜欢
    • 2018-09-01
    • 2017-11-20
    • 2018-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-24
    • 2019-02-02
    • 1970-01-01
    相关资源
    最近更新 更多