简体   繁体   中英

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_()

With this code, I am trying to save the information that I received from the user to the Firebase database, but I keep getting "Process finished with exit code -1073740791 (0xC0000409)" error. I decided to use exception handling but this time "try:" block doesn't work. Maybe i shouldn't use the authentication method to register user. Any advice?

so here is the.ui files

Register screen ui file is in the below

<?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>

Login screen ui is at the below

<?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>

If you want to know the cause of the error then you should run the script in the console to get a more descriptive message instead of a numerical code.

I see that the logic is messy, in this case I prefer to have a class that only handles the logic of authentication or user creation:

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_()

Note: The requests are being executed in a second thread since these tasks can take a long time blocking the GUI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM