【问题标题】:Kivy Buildozer: AttributeError: 'NoneType' object has no attribute 'text'Kivy Buildozer:AttributeError:“NoneType”对象没有属性“文本”
【发布时间】:2020-04-03 01:33:43
【问题描述】:

我正在使用 Buildozer 测试 Kivy,以便为我的 Android 设备制作一个小应用程序。在我的电脑上,everythink 运行正常。但是当我想每次都用 Buildozer 创建 APK 时出现错误 AttributeError: 'NoneType' object has no attribute 'text'

我用谷歌搜索了很多次,但我找不到我的问题的答案。

有人给我提示吗?

会很棒。

谢谢!

main.py:

import kivy
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout  
from kivy.uix.textinput import TextInput  
import random
from kivy.clock import Clock
from kivy.properties import ObjectProperty
import requests
import json

def login (name,password):
    url_login = 'URL'
    payload = {'email': name, 'password': password}
    headers = {'content-type': 'application/json'}
    r = requests.post(url_login, data=json.dumps(payload), headers=headers).json()
    return (r['token'])
token =login("ID","PW")

class ConnectPage(GridLayout):
    oee = ObjectProperty(None)
    performance = ObjectProperty(None)
    quality = ObjectProperty(None)
    availability = ObjectProperty(None)
    sensorstandort = ObjectProperty(None)
    schicht = ObjectProperty(None)
    timestamp = ObjectProperty(None)
    alert = ObjectProperty(None)

    def oee_anzeige(self, *args):
        #Anfrage an Server senden
        url_report = 'URL/'
        payload_report = {}
        headers_report = {'content-type': 'application/json', 'Authorization': token}
        r_report = requests.get(url_report, data=json.dumps(payload_report), headers=headers_report)
        response = r_report.json()

        #Schicht, Sensorstandort und ggfs. Störgrund raussuchen
        x = 0
        for i in response['included']:
            if response['included'][x]['type'] == 'shift':
                schicht = response['included'][x]['attributes']['name']
            if response['included'][x]['type'] == 'location':
                sensorstandort = response['included'][x]['attributes']['name']
            if response['included'][x]['type'] == 'notification':

                timestamp = str(response['included'][x]['attributes']['inserted-at'])
                timestamp = timestamp[11:16] + ' Uhr'

                #self.timestamp.text = timestamp
                if response['included'][x]['attributes']['triggered-by'] == 'standstill':
                    self.alert.text = "Verfügbarkeitsverlust seit"
                elif sensorstandort == response['included'][x]['attributes']['triggered-by'] == 'slowdown':
                    self.alert.text = "Leistungsverlust seit"
            x +=1






        #oee Werte aus API ziehen
        oee = str(response['data']['attributes']['oee']) + " %"
        availability = str(response['data']['attributes']['availability']) + " %"
        performance =str(response['data']['attributes']['performance']) + " %"
        quality = str(response['data']['attributes']['quality']) + " %"




        #Labels definieren
        self.oee.text = oee
        self.availability.text = availability
        self.performance.text = performance
        self.quality.text = quality
        self.sensorstandort.text = sensorstandort
        self.schicht.text = schicht


    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.cols = 2  # used for our grid


class EpicApp(App):
    def build(self):
        t = ConnectPage()
        Clock.schedule_once(t.oee_anzeige, 2)
        Clock.schedule_interval(t.oee_anzeige, 90)
        return t



if __name__ == "__main__":
    EpicApp().run()



史诗.kv


<ConnectPage>:





    oee:oee
    availability: availability
    performance: performance
    quality: quality
    sensorstandort: sensorstandort
    schicht: schicht
    alert: alert
    timestamp: timestamp

    GridLayout:
        cols: 2


        Label:
            text: "wird geladen"
            id: sensorstandort
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

        Label:
            text: "wird geladen"
            id: schicht
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

        Label:
            text: "OEE"
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

        Label:
            text: "wird geladen"
            id: oee
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]



        Label:
            text: "Verfügbarkeit"
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

        Label:
            text: "Wird geladen"
            id: availability
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]



        Label:
            text: "Leistung"
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

        Label:
            text: "Wird geladen"
            id: performance
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]


        Label:
            text: "Qualität"
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

        Label:
            text: "Wird geladen"
            id: quality
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]


        Label:
            text:
            id: alert
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

        Label:
            text:
            id: timestamp
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

来自 Buildozer Logcat 的日志:

....
04-01 19:37:22.029 19854 19881 I python  :  Traceback (most recent call last):
04-01 19:37:22.030 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/app/main.py", line 97, in <module>
04-01 19:37:22.031 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/app.py", line 855, in run
04-01 19:37:22.032 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py", line 504, in runTouchApp
04-01 19:37:22.034 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2.py", line 747, in mainloop
04-01 19:37:22.035 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2.py", line 479, in _mainloop
04-01 19:37:22.035 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py", line 339, in idle
04-01 19:37:22.036 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/clock.py", line 591, in tick
04-01 19:37:22.037 19854 19881 I python  :    File "kivy/_clock.pyx", line 384, in kivy._clock.CyClockBase._process_events
04-01 19:37:22.037 19854 19881 I python  :    File "kivy/_clock.pyx", line 414, in kivy._clock.CyClockBase._process_events
04-01 19:37:22.038 19854 19881 I python  :    File "kivy/_clock.pyx", line 412, in kivy._clock.CyClockBase._process_events
04-01 19:37:22.039 19854 19881 I python  :    File "kivy/_clock.pyx", line 167, in kivy._clock.ClockEvent.tick
04-01 19:37:22.040 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/app/main.py", line 52, in oee_anzeige
04-01 19:37:22.041 19854 19881 I python  :  AttributeError: 'NoneType' object has no attribute 'text'
04-01 19:37:22.041 19854 19881 I python  : Python for android ended.
....
04-01 19:44:07.500 20768 20788 I python  :  Traceback (most recent call last):
04-01 19:44:07.501 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/app/main.py", line 97, in <module>
04-01 19:44:07.502 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/app.py", line 855, in run
04-01 19:44:07.503 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py", line 504, in runTouchApp
04-01 19:44:07.504 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2.py", line 747, in mainloop
04-01 19:44:07.504 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2.py", line 479, in _mainloop
04-01 19:44:07.505 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py", line 339, in idle
04-01 19:44:07.505 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/clock.py", line 591, in tick
04-01 19:44:07.506 20768 20788 I python  :    File "kivy/_clock.pyx", line 384, in kivy._clock.CyClockBase._process_events
04-01 19:44:07.507 20768 20788 I python  :    File "kivy/_clock.pyx", line 414, in kivy._clock.CyClockBase._process_events
04-01 19:44:07.507 20768 20788 I python  :    File "kivy/_clock.pyx", line 412, in kivy._clock.CyClockBase._process_events
04-01 19:44:07.508 20768 20788 I python  :    File "kivy/_clock.pyx", line 167, in kivy._clock.ClockEvent.tick
04-01 19:44:07.508 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/app/main.py", line 52, in oee_anzeige
04-01 19:44:07.509 20768 20788 I python  :  AttributeError: 'NoneType' object has no attribute 'text'
04-01 19:44:07.509 20768 20788 I python  : Python for android ended.
04-01 19:48:13.346 21723 21762 I python  : Initializing Python for Android
04-01 19:48:13.347 21723 21762 I python  : Setting additional env vars from p4a_env_vars.txt
04-01 19:48:13.347 21723 21762 I python  : Changing directory to the one provided by ANDROID_ARGUMENT
04-01 19:48:13.347 21723 21762 I python  : /data/user/0/org.test.oeecloud/files/app
04-01 19:48:13.356 21723 21762 I python  : Preparing to initialize python
04-01 19:48:13.356 21723 21762 I python  : _python_bundle dir exists
04-01 19:48:13.356 21723 21762 I python  : calculated paths to be...
04-01 19:48:13.356 21723 21762 I python  : /data/user/0/org.test.oeecloud/files/app/_python_bundle/stdlib.zip:/data/user/0/org.test.oeecloud/files/app/_python_bundle/modules
04-01 19:48:13.380 21723 21762 I python  : set wchar paths...
04-01 19:48:13.420 21723 21762 I python  : Initialized python
04-01 19:48:13.420 21723 21762 I python  : AND: Init threads
04-01 19:48:13.421 21723 21762 I python  : testing python print redirection
04-01 19:48:13.422 21723 21762 I python  : Android path ['.', '/data/user/0/org.test.oeecloud/files/app/_python_bundle/stdlib.zip', '/data/user/0/org.test.oeecloud/files/app/...
'P4A_MINSDK': '21', 'LC_CTYPE': 'C.UTF-8'})
...
04-01 19:48:16.306 21723 21762 I python  : [INFO   ] [Base        ] Leaving application in progress...
04-01 19:48:16.307 21723 21762 I python  :  Traceback (most recent call last):
04-01 19:48:16.309 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/app/main.py", line 97, in <module>
04-01 19:48:16.311 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/app.py", line 855, in run
04-01 19:48:16.312 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py", line 504, in runTouchApp
04-01 19:48:16.312 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2.py", line 747, in mainloop
04-01 19:48:16.313 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2.py", line 479, in _mainloop
04-01 19:48:16.314 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py", line 339, in idle
04-01 19:48:16.314 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/clock.py", line 591, in tick
04-01 19:48:16.315 21723 21762 I python  :    File "kivy/_clock.pyx", line 384, in kivy._clock.CyClockBase._process_events
04-01 19:48:16.315 21723 21762 I python  :    File "kivy/_clock.pyx", line 414, in kivy._clock.CyClockBase._process_events
04-01 19:48:16.315 21723 21762 I python  :    File "kivy/_clock.pyx", line 412, in kivy._clock.CyClockBase._process_events
04-01 19:48:16.316 21723 21762 I python  :    File "kivy/_clock.pyx", line 167, in kivy._clock.ClockEvent.tick
04-01 19:48:16.316 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/app/main.py", line 52, in oee_anzeige
04-01 19:48:16.317 21723 21762 I python  :  AttributeError: 'NoneType' object has no attribute 'text'
04-01 19:48:16.317 21723 21762 I python  : Python for android ended.




【问题讨论】:

    标签: python python-3.x kivy buildozer


    【解决方案1】:

    .py 文件中的这行代码抛出错误

     #self.timestamp.text = timestamp
                    if response['included'][x]['attributes']['triggered-by'] == 'standstill':
                        self.alert.text = "Verfügbarkeitsverlust seit"
                    elif sensorstandort == response['included'][x]['attributes']['triggered-by'] == 'slowdown':
                        self.alert.text = "Leistungsverlust seit"
                x +=1
    

    我通过查看您发布的日志获得了此信息,该日志表明line 52main.py 文件中存在错误

    04-01 19:44:07.508 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/app/main.py", line 52, in oee_anzeige
    04-01 19:44:07.509 20768 20788 I python  :  AttributeError: 'NoneType' object has no attribute 'text'
    04-01 19:44:07.509 20768 20788 I python  : Python for android ended.
    

    【讨论】:

    • 您好,谢谢。我试图取消注释此任务,但错误仍然发生并转到第 74 行“self.oee.text = oee” 我认为 .text 有问题。但不寻常的是,我的脚本可以在我的电脑上运行
    • 据我所知,时间戳、oeee、可用性、性能等是标签的 id。所以你需要参考Widget的具体属性。比如可以做oeee.text或者oeee.width等,不能只引用oeee
    • 你能再解释一下吗?我将变量编辑为例如“oee_”并在最后使用 self.oee.text = ... 进行标签操作,但这不是问题:(
    • for self.oee.text = oee 尝试使用 self.ids.oee.text = oee 看看是否成功 // 使用最新信息更新错误日志和代码
    • 您好,感谢您的快速回复。我改变了这个,现在我得到另一个错误
    【解决方案2】:

    您好,感谢您的快速回复。 我改变了这个东西,现在我得到一个新的错误

    attributeerror 'super' object has no attribute '__getattr__' kivy
    

    我在 Google 上搜索并将我的 super.init 编辑为 super(ConnectPage, self).__init__(**kwargs) 但是这个错误还是会出现。

    你还有什么要告诉我的吗? 谢谢! 日志说:

    04-02 19:25:36.760 12173 12330 I python:回溯(最近一次通话最后一次): 04-02 19:25:36.762 12173 12330 I python:文件“kivy/properties.pyx”,第 860 行,在 kivy.properties.ObservableDict.getattr 04-02 19:25:36.764 12173 12330 I python:KeyError:“可用性” 04-02 19:25:36.765 12173 12330 我蟒蛇:
    04-02 19:25:36.766 12173 12330 I python:在处理上述异常的过程中,又发生了一个异常: 04-02 19:25:36.766 12173 12330 我蟒蛇:
    04-02 19:25:36.766 12173 12330 I python:回溯(最近一次通话最后一次): 04-02 19:25:36.767 12173 12330 I python:文件“/home/julian/kivy/.buildozer/android/app/main.py”,第 96 行,在 04-02 19:25:36.768 12173 12330 I python:文件“/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/app.py”,第 855 行,运行中 04-02 19:25:36.768 12173 12330 I python:文件“/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py”,第 504 行,在 runTouchApp 中 04-02 19:25:36.769 12173 12330 I python:文件“/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2 .py”,第 747 行,在主循环中 04-02 19:25:36.770 12173 12330 I python:文件“/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2 .py”,第 479 行,在 _mainloop 04-02 19:25:36.771 12173 12330 I python:文件“/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py”,第 339 行,空闲 04-02 19:25:36.773 12173 12330 I python:文件“/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/clock.py”,第 591 行,刻度线 04-02 19:25:36.775 12173 12330 I python:文件“kivy/_clock.pyx”,第 384 行,在 kivy._clock.CyClockBase._process_events 04-02 19:25:36.777 12173 12330 I python:文件“kivy/_clock.pyx”,第 414 行,在 kivy._clock.CyClockBase._process_events 04-02 19:25:36.777 12173 12330 I python:文件“kivy/_clock.pyx”,第 412 行,在 kivy._clock.CyClockBase._process_events 04-02 19:25:36.778 12173 12330 I python:文件“kivy/_clock.pyx”,第 167 行,在 kivy._clock.ClockEvent.tick 04-02 19:25:36.779 12173 12330 I python:文件“/home/julian/kivy/.buildozer/android/app/main.py”,第 75 行,位于 oee_anzeige 04-02 19:25:36.779 12173 12330 I python:文件“kivy/properties.pyx”,第 863 行,在 kivy.properties.ObservableDict.getattr 04-02 19:25:36.780 12173 12330 I python:AttributeError:'super'对象没有属性'getattr' 04-02 19:25:36.780 12173 12330 I python : Python for android 结束了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多