导入robobrowser时Android python应用程序崩溃

时间:2019-07-19 15:28:47

标签: python android python-requests kivy robobrowser

我想用python编写android应用程序。应用程序应从互联网下载用户(由应用程序登录的)数据。

我尝试将kivy与robobrowser结合使用,并且在计算机设备上可以正常工作,但是在用buildozer部署并在android应用程序崩溃时运行它之后。

我应该怎么做才能使其在android上运行,或者我应该使用其他哪些库或框架?

编辑: 我来自main.py的代码:

from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import StringProperty
from kivy.properties import ObjectProperty

Builder.load_string("""

<LogIn>:
    email_input: email
    password_input: password

    BoxLayout:
        size_hint_y: None
        height: "40dp"

        Label:
            id: logged
            text: root.log

        Label:
            text: "email"
        TextInput:
            id: email

        Label:
            text: "password"
        TextInput:
            id: password
        Button:
            text: "submit"
            on_press: root.logIn()

""")


from robobrowser import RoboBrowser
class LogIn(Screen):
    log = StringProperty()

    def __init__(self, **kwargs):
        super(LogIn, self).__init__(**kwargs)
        self.log = str("label")

    def logIn(self):
        br = RoboBrowser()
        br.open('https://git-scm.com/download/linux')
        self.log = str(br.parsed)[0:10]




# import requests
# class LogIn(Screen):
#     log = StringProperty()
#
#     def __init__(self, **kwargs):
#         super(LogIn, self).__init__(**kwargs)
#         self.log = str("label")
#
#     def logIn(self):
#         res = requests.get('https://git-scm.com/download/linux')
#         self.log = str(res.text)[0:10]





class testApp(App):
    def build(self):
        return LogIn()


if __name__ == '__main__':
    testApp().run()

具有三个标签,两个输入文本和提交按钮的应用程序创建窗口。单击“提交”按钮后,其中一个标签应在我要抓取的页面代码的10个首个符号上更改其文本。

输入以下版本的代码(无注释的robobrowser部分)

buildozer android debug deploy

然后创建.apk文件。将此文件移到我的智能手机上的/ storage / emulated / 0目录中并安装应用程序后,在启动过程中会崩溃。但是,当我评论robobrowser部分和uncomment请求部分并在我的智能手机上安装aplication时,当我按下Submit按钮时,它就会崩溃。

另外,当使用robobrowser部分创建应用时,请在buildozer.spec中写入要求:

requirements = python3,robobrowser,kivy

,然后在“请求”部分尝试时输入:

requirements = python3,requests,kivy

所以我想找出为什么应用程序在android设备上崩溃的原因。

EDIT2: 我设法通过buildozer.spec文件中的注释行避免请求部分崩溃:

android.permissions = INTERNET

但是当使用robobrowser部分并想知道为什么时它仍然崩溃。

0 个答案:

没有答案