Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

Kivy Buildozer: aiohttp asyncio Issue, App Crashes

$
0
0

I will try to expain my problem exactly.First of all, my kivy app and its all sections works in VScode.It is a calculator app that scrape some datas and calculate them

Python version: 3.11.7Kivy version: 2.3.0

I have two functions in my code so i want them to work together at the same time so i used aiohttp asyncio. Lets start

Libraries that i used in my app

from kivy.app import Appfrom kivy.uix.boxlayout import BoxLayoutfrom kivy.uix.label import Labelfrom kivy.uix.image import Imagefrom kivy.uix.behaviors import ButtonBehaviorfrom kivy.metrics import dpfrom kivy.clock import mainthreadfrom kivy.uix.popup import Popupfrom kivy.factory import Factoryfrom kivy.properties import ObjectPropertyfrom time import sleepfrom unidecode import unidecodefrom bs4 import BeautifulSoupimport aiohttpimport asyncioimport requestsimport threadingimport re 

Code example of aiohttp / asyncio

@mainthread    def calculate(self, lig, *args):        async def fetch_stats_home(session, url, match_codes_home):            try:                querystring = {}                headers = {}                async with session.get(url, params=querystring, headers=headers) as response:                    soup = BeautifulSoup(await response.text(), "html.parser")        async def fetch_stats_away(session, url, match_codes_away):            try:                querystring = {}                headers = {}                async with session.get(url, params=querystring, headers=headers) as response:                    soup = BeautifulSoup(await response.text(), "html.parser")                              except:                pass                 async def main():            url = "https://Handler.aspx"                match_codes_home = evsahibi_evindeki_maclar_kodlar            match_codes_away = deplasman_deplasmandki_maclar_kodlar              async with aiohttp.ClientSession() as session:                tasks_home  = [fetch_stats_home(session, url, match_code) for match_code in match_codes_home]                tasks_away  = [fetch_stats_away(session, url, match_code) for match_code in match_codes_away]                await asyncio.gather(*tasks_home, *tasks_away)        asyncio.run(main())

VSCODE TESTS & Terminal Logs (APP Works Without a Problem)

[DEBUG  ] [Using proactor] IocpProactor[DEBUG  ] [Starting new HTTPS connection (1)] .com:443[DEBUG  ] [https          ]//.com:443 "GET /Takim/451/ HTTP/1.1" 200 27720[DEBUG  ] [https          ]//.com:443 "GET /Takim/570/ HTTP/1.1" 200 28575[DEBUG  ] [Using proactor] IocpProactor[DEBUG  ] [Starting new HTTPS connection (1)] arsiv.mackolik.com:443[DEBUG  ] [https          ]//.com:443 "GET /Takim/3/ HTTP/1.1" 200 29920[DEBUG  ] [https          ]//:443 "GET /Takim/447/ HTTP/1.1" 200 28574[DEBUG  ] [Using proactor] IocpProactor[DEBUG  ] [Starting new HTTPS connection (1)] arsiv.mackolik.com:443[DEBUG  ] [https          ]//:443 "GET /Takim/8/ HTTP/1.1" 200 28140[DEBUG  ] [https          ]//:443 "GET /Takim/448/ HTTP/1.1" 200 28235[DEBUG  ] [Using proactor] IocpProactorScroll 1APP WORKS

BUILDOZER: i compiled app in Buildozer, when i click Calculate button then APP crashes.

Here is the log : adb logcat -s python

As you can see, at the first [Using proactor] IocpProactor , APP Crashes.

Starting new HTTPS connection (1)] arsiv.mackolik.com:44302-17 13:59:55.087 12778 13111 I python  : [DEBUG  ] [https          ]//arsiv.mackolik.com:443 "GET /Takim/574/ HTTP/1.1" 200 2772002-17 13:59:56.036 12778 13111 I python  : [DEBUG  ] [https          ]//arsiv.mackolik.com:443 "GET /Takim/446/ HTTP/1.1" 200 2857502-17 13:59:56.346 12778 13111 I python  : [DEBUG  ] [Using selector] EpollSelector02-17 13:59:56.762 12778 13111 I python  : [INFO   ] [Base        ] Leaving application in progress...02-17 13:59:56.763 12778 13111 I python  :  Traceback (most recent call last):02-17 13:59:56.763 12778 13111 I python  :    File "/home/seo/Desktop/APP/.buildozer/android/app/main.py", line 825, in <module>02-17 13:59:56.763 12778 13111 I python  :    File "/home/seo/Desktop/APP/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/footballpredictor/arm64-v8a/kivy/app.py", line 956, in run02-17 13:59:56.763 12778 13111 I python  :    File "/home/seo/Desktop/APP/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/footballpredictor/arm64-v8a/kivy/base.py", line 574, in runTouchApp02-17 13:59:56.764 12778 13111 I python  :    File "/home/seo/Desktop/APP/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/footballpredictor/arm64-v8a/kivy/base.py", line 339, in mainloop02-17 13:59:56.764 12778 13111 I python  :    File "/home/seo/Desktop/APP/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/footballpredictor/arm64-v8a/kivy/base.py", line 379, in idle02-17 13:59:56.764 12778 13111 I python  :    File "/home/seo/Desktop/APP/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/footballpredictor/arm64-v8a/kivy/clock.py", line 733, in tick02-17 13:59:56.765 12778 13111 I python  :    File "/home/seo/Desktop/APP/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/footballpredictor/arm64-v8a/kivy/clock.py", line 776, in post_idle02-17 13:59:56.765 12778 13111 I python  :    File "kivy/_clock.pyx", line 620, in kivy._clock.CyClockBase._process_events02-17 13:59:56.765 12778 13111 I python  :    File "kivy/_clock.pyx", line 653, in kivy._clock.CyClockBase._process_events02-17 13:59:56.765 12778 13111 I python  :    File "kivy/_clock.pyx", line 649, in kivy._clock.CyClockBase._process_events02-17 13:59:56.766 12778 13111 I python  :    File "kivy/_clock.pyx", line 218, in kivy._clock.ClockEvent.tick02-17 13:59:56.766 12778 13111 I python  :    File "/home/seo/Desktop/APP/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/footballpredictor/arm64-v8a/kivy/clock.py", line 1095, in callback_func02-17 13:59:56.766 12778 13111 I python  :    File "/home/seo/Desktop/APP/.buildozer/android/app/main.py", line 598, in calculate02-17 13:59:56.766 12778 13111 I python  :  ZeroDivisionError: division by zero02-17 13:59:56.766 12778 13111 I python  : Python for android ended.

Buildozer.spec

requirements = python3==3.11.7,kivy==2.3.0,aiohttp==3.9.3,aiosignal==1.3.1,attrs==23.2.0,beautifulsoup4==4.12.3,certifi==2024.2.2,charset-normalizer==3.3.2,docutils==0.20.1,frozenlist==1.4.1,idna==3.6,multidict==6.0.5,requests==2.31.0,soupsieve==2.5,Unidecode==1.3.8,urllib3==2.2.0,yarl==1.9.4osx.python_version = 3.11.7osx.kivy_version = 2.3.0

UPDATE Found Problem but can't fixed

When i create APK via buildozer, i checked with"buildozer android debug deploy run logcat" that'async with session.get(url, params=querystring, headers=headers) as response:'sections do not work and also beautifulsoup which is inside does not work as well so data is not scraped! and we get ZeroDivisionError

But in VSCODE there are no problem.

Why 'async with session.get(url, params=querystring, headers=headers) as response:' part does not work in kivy?

Thanks


Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>