I think this app explains how Kivy's UrlRequest works:
from kivy.network.urlrequest import UrlRequest
from kivy.app import App
from kivy.uix.button import Button
class reqApp(App):
def build(self):
bt = Button(text='Pegar Json do Bitcoin')
bt.bind(on_press=self.make_request)
return bt
def make_request(self, instance):
UrlRequest('https://www.mercadobitcoin.net/api/BTC/ticker/', self.print_json)
def print_json(self, req, result):
print result['ticker']
if __name__ == '__main__':
reqApp().run()
When you click the button it calls the make_request
that makes an instance of UrlRequest
. When the object is instantiated, it automatically makes an asynchronous request and when it finishes (if the request succeeds) it calls the function print_json
.
Remember it's asynchronous so the GUI main loop will not "hang" until the request is finished, there is no need to use the python threads.
To get all the details of the parameters that you can pass in UrlRequest see link
PS: I use the library requests in android in an app that made music and works normal if you want to see: link
If it is very simple you can use the standard python library urllib2