I'm trying to make a simple Kivy app (my first, have patience) that sends two parameters to my localhost (Flask) and gets 2 strings in return. A label should show the string values.
When I don't use Kivy the following code works:
import requests
payload = {'key1': 'value1', 'key2': 'value2'}
r = requests.get('http://127.0.0.1:5000/', params=payload)
print r.text
My console shows me "value1value2". Obviously, because it's the example code I copied from the documentation...
Now, when I put the same code in a Kivy app like this:
from kivy.app import App
from kivy.lang import Builder
from kivy.properties import StringProperty
import requests
kv = '''
BoxLayout:
orientation: 'vertical'
Label:
text: app.text
Button:
text: 'call Flask'
on_press: app.clicked()
'''
class MyApp(App):
text = StringProperty("Show me the Params!")
def build(self):
return Builder.load_string(kv)
def clicked(self):
payload = {'key1': 'value1', 'key2': 'value2'}
r = requests.get('http://127.0.0.1:5000/', params=payload)
self.text = str(r)
print r
if __name__ == '__main__':
MyApp().run()
I get no errors, but the label shows "Response[200]", in stead of the string values ("value1value2")...
I know this is the http status code, but why do I get it here? I want my values! ;-)
Anyone a clue?
Added code (for text entry):
from kivy.app import App
from kivy.lang import Builder
from kivy.properties import StringProperty
import requests
kv = '''
BoxLayout:
orientation: 'vertical'
Label:
text: app.text
Button:
text: 'call Flask'
on_press: app.clicked()
TextInput:
id: text_input
'''
class MyApp(App):
text = StringProperty("Show me the Params!")
intxt = StringProperty("Input_text")
def build(self):
return Builder.load_string(kv)
def clicked(self):
payload = {'key1': self.intxt, 'key2': 'value2'}
r = requests.get('http://127.0.0.1:5000/', params=payload)
self.text = str(r.content)
print r.content
if __name__ == '__main__':
MyApp().run()
Access content
property of requests
object r
.
print r.content
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments