当我使用mysql Localhost时,APK应用程序崩溃了



我刚刚完成了应用程序接口的设计,并将其连接到MySql数据库以发送和检索数据,我很兴奋能将其转换为APK文件并在我的Android上进行测试,应用程序运行良好,但每当我尝试与数据库通信时,应用程序都会崩溃,甚至我也在使用try,Except语句

在这一点上,我想我仍然缺少一些东西来连接我在android上的应用程序和我在PC上的localhost数据库。

这是我的连接代码:

class FifthScreen(Screen):
users = os.environ.get('USER_NAME')
pass_word = os.environ.get('WORDPASS')
try:
database = mysql.connector.connect(host="localhost", user=users, password=pass_word, database="logintest", port= "3306")
cursor = database.cursor()
except Error as e:
print(e)
admin_email = "rasheed@hotmail.com"
admin_password = "King"
loggedin = False
def receive_data(self, email, password):
try:
self.cursor.execute("select email,password from logs")
email_list = []
for i in self.cursor.fetchall():
email_list.append(i[0])
if email.text in email_list and email.text != "":
self.cursor.execute(f"select password,user_name from logs where email='{email.text}'")
for j in self.cursor:
if email.text == self.admin_email and password.text == self.admin_password:
print("Hello Admin")
self.manager.current = 'Data_Table'
elif password.text == j[0]:
print("you successfully logged in")
self.manager.current = 'Doctors_Patients_Details'
self.loggedin = True
self.manager.get_screen('photo_page').ids.user_name.text = j[1]
else:
print("incorrect password ")
else:
print("incorrect email")
except Error as e:
print(e)
finally:
if self.database.is_connected():
self.database.close()
self.cursor.close()
print("closed4")

以下是要求:

requirements =  python3,kivy==2.1.0,kivymd==0.104.2,pillow, requests,android,docutils,mysql_connector,mysql-connector-python,fpdf
android.permissions = INTERNET,READ_EXTERNAL_STORAGE,WRITE_EXTERNAL_STORAGE

因此,我需要一些关于在android上的应用程序和pc上的数据库之间连接的方法或工具的指南。我使用的是Kivy、Python3和mysql-db,我现在使用的是本地主机,我没有错过在buildozer规范文件中授予android权限。

编辑零件:我添加了IP地址而不是本地主机,端口3306,并阻止了防火墙我面临两个问题:1-与数据库通信后再次崩溃

class FifthScreen(Screen):
users = os.environ.get('USER_NAME')
pass_word = os.environ.get('WORDPASS')
try:
database = mysql.connector.connect(host="192.168.43.64", user=users, password=pass_word, database="logintest", port= "3306")
cursor = database.cursor()


Traceback (most recent call last):
10-25 21:19:50.841  3641  4045 I python  :    File "/content/.buildozer/android/app/main.py", line 328, in receive_data
10-25 21:19:50.843  3641  4045 I python  :  AttributeError: 'FifthScreen' object has no attribute 'cursor' 
AttributeError: 'FifthScreen' object has no attribute 'database'
10-25 21:19:50.848  3641  4045 I python  : Python for android ended.

2-防溅屏后的黑屏在 3到4分钟左右粘得太久

win=Window{3e4abc u0 Splash Screen org.test.test3 EXITING} destroySurfaces: appStopped=false win.mWindowRemovalAllowed=true win.mRemoveOnExit=true 

我解决了这个问题,这是一个愚蠢的错误,但我想分享这个问题,因为任何像我这样的新手都可能陷入同样的错误,

我在MySQL中创建了远程用户,并为其提供了包含特殊字符(&(的密码,由于某些原因,您无法访问带有特殊字符的服务器。这就是整个问题:(

最新更新