strange difference in python behavior with Requests, Flask and Kivy

Erik van Elten

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()
Avinash Raj

Access content property of requests object r.

print r.content

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Python socket strange behavior

From Java

Strange behavior with python slicing

From Java

Python strange behavior with enumerate

From Dev

Strange behavior of Python 'is'

From Dev

Python: Strange behavior of locals()

From Dev

Strange behavior of python function

From Dev

Strange behavior with python dictionary

From Dev

Strange filter behavior in flask-sqlalchemy

From Dev

Python email header strange behavior

From Dev

Python 2.7: Strange Unicode behavior

From Dev

Python Recursive Function Strange Behavior

From Dev

python numpy arange: strange behavior

From Dev

Python : strange behavior with matplotlib barchart

From Dev

Python replace method strange behavior

From Dev

strange behavior of constant 'e' in Python

From Dev

How to combine flask and requests in python?

From Dev

Strange Python 3 mod behavior for longs

From Dev

Strange behavior of Python (IndentationError: unexpected indent) - Why?

From Java

Python __getitem__ and in operator result in strange behavior

From Dev

Strange behavior involving Python nested lists

From Python

Strange behavior with Python 3 re.sub

From Dev

Strange print behavior with time.sleep in python

From Dev

Python 2.7 class attribute strange behavior

From Dev

try except strange behavior python 2.7

From Dev

Strange behavior in Python 3 using the sys module

From Dev

Import from relative path in Python: strange behavior

From Dev

super() strange behavior in diamond inheritance in python

From Dev

Strange stacked range() loop behavior python

From Dev

strange class behavior in the python pattern decorator