Reputation: 1
I'm making a simple app to (in the future) see some stuff from a webpage. At the moment it works perfectly on windows( it logs in and gives a new page).But it stopped working on my phone. It won't launch with kivy launcher. It can't be too big for it. I have no idea what is the problem. I have tried everything... Here's my code:
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
import kivy
kivy.require('1.8.0')
import webbrowser
import urllib.request
import re
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty, StringProperty
from kivy.network.urlrequest import UrlRequest
from kivy.uix.popup import Popup
from kivy.lang import Builder
Builder.load_string("""
<Phone>:
sm: _screen_manager
usernameField: username
passwordField: password
AnchorLayout:
anchor_x: 'center'
anchor_y: 'top'
ScreenManager:
size_hint: 1, .9
id: _screen_manager
Screen:
name: 'Avakuva'
Label:
markup: True
text: '[size=50]Welcome to [color=8b00c3]Pelltech app![/color][/size]'
FloatLayout:
Button:
text: 'Info'
size_hint: .2, .1
pos_hint: {'x': .3, 'y': .1}
on_press: _screen_manager.current = 'Info'
Button:
text: 'Login'
size_hint: .2, .1
pos_hint: {'x': .5, 'y': .1}
on_press: _screen_manager.current = 'Login'
Screen:
name: 'Login'
GridLayout:
rows: 3
cols: 2
padding: 200
spacing: 10
Label:
text: 'User name:'
TextInput:
id: username
Label:
text: 'Password:'
TextInput:
id: password
password: True
Label:
text:''
Button:
text:"Log in"
on_press: root.goToBurners(username.text, password.text)
Screen:
name: 'Info'
GridLayout:
rows:2
cols:1
padding: 200
spacing: 10
Label:
haling: 'justify'
text:'This app is for pelletburner owners. For more information contact:'
Button:
text:'Pelltech'
on_press: root.openPage()
FloatLayout:
Button:
text: 'Back'
size_hint: .2, .1
pos_hint: {'x': .4, 'y': .1}
on_press: _screen_manager.current = 'Avakuva'
Screen:
name: 'Menu'
GridLayout:
rows:3
cols:1
padding:200
spacing: 10
Label:
markup: True
text: 'Menüü:'
Button:
text: 'Minu põletid'
on_press: _screen_manager.current = 'põletid'
Button:
text: 'Muu'
Screen:
name: 'põletid'
GridLayout:
rows:4
cols:1
padding: 200
spacing: 10
Label:
markup: True
text: 'Burner 1'
Label:
markup: True
text: 'Burner 2'
Label:
markup: True
text: 'Burner 3'
Button:
text: 'Back'
size: 50, 50
on_press: _screen_manager.current = 'Menu'
""")
class Phone(FloatLayout):
def openPage(self):
webbrowser.open('http://www.pelltech.eu')
def goToBurners(self, username, password):
#import pdb; pdb.set_trace()
print("1")
params = urllib.parse.urlencode({'username':username, 'password':password, 'nextPage':'/'})
headers={'Content-type':'application/x-www-form-urlencoded','Accept':'text/plain'}
print("2")
req = UrlRequest('http://10.1.1.116/account/login?',req_headers=headers, req_body=params, method = "POST", on_redirect = self.gotResults, on_success=self.loginSuccess, on_failure=self.connectionFail)
timeout = 10
def newSuccess(self, req, result):
print("new success")
print(req.resp_status)
print(result.decode())
sm=ObjectProperty(ScreenManager())
self.sm.current = 'Menu'
def newFail(self, req, result):
print("new fail")
print(req.resp_status)
print(result.decode())
def newRedirect(self, req, result):
print("new redirect")
print(req.resp_status)
print(result.decode())
def gotResults(self, req, result):
print(req.resp_status)
print('on_redirect tõi siia')
#print(req.resp_headers)
headerText = str(req.resp_headers)
cookieStart = headerText.find('sessionid')
#cookieEnd = headerText.find('expires')-2
cookieEnd = headerText.find('=/')+2
cookie = headerText[cookieStart:cookieEnd]
print(cookie)
headers={'Cookie': cookie}
req = UrlRequest('http://10.1.1.116/',req_headers=headers, method = "POST", on_redirect = self.newRedirect, on_success=self.newSuccess, on_failure=self.newFail)
def loginSuccess(self, req, result):
print(req.resp_status)
print("on_success t6i siia")
print (result.decode())
content = Button(text = 'Proovi uuesti!', size = (20,20))
popup = Popup(title= 'Login ebaõnnestus!', content = content, size_hint = (None, None), size = (400,400), auto_dismiss = False)
content.bind(on_press = popup.dismiss)
popup.open()
self.usernameField.text = ""
self.passwordField.text = ""
def connectionFail(self, req, result):
print("on_failure t6i siia")
print(req.resp_status)
content = Button(text = 'Proovi uuesti!', size = (20,20))
popup = Popup(title= 'Ühendus serveriga puudub!', content = content, size_hint = (None, None), size = (400,400), auto_dismiss = False)
content.bind(on_press = popup.dismiss)
popup.open()
class TestApp(App):
def build(self):
return Phone()
if __name__ == '__main__':
TestApp().run()
Upvotes: 0
Views: 3002
Reputation: 11
I have same issue in past and I solve by adding requirements in .spec
This requirements work for me:
requirements = hostpython3==3.7.8,python3==3.7.8,kivy==1.11.1, certifi,chardet, lxml, docutils, future, idna, Kivy-Garden, Pygments, requests, six, soupsieve, urllib3, deep-translator, arabic-reshaper, python-bidi, openssl, pyopenssl, numpy, pytz, python-dateutil, pandas, setuptools, zope.interface, datetime
you have to write all modules and parent module in requirements which your app is using.
To know module which you app is using has two method:
Upvotes: 0
Reputation: 29488
You should follow the debug instructions in the kivy documentation, and paste the logcat output here if it doesn't make the answer clear.
Upvotes: 1