Skip to content

Instantly share code, notes, and snippets.

@rohman
Created April 3, 2013 11:52
Show Gist options
  • Save rohman/5300550 to your computer and use it in GitHub Desktop.
Save rohman/5300550 to your computer and use it in GitHub Desktop.
Sample Rest With Kivy
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.network.urlrequest import UrlRequest
class Example(FloatLayout):
def __init__(self, **kwargs):
super(Example, self).__init__(**kwargs)
def on_success(req, result, *args):
#print result
res = result
layout = BoxLayout(orientation='vertical')
for item in res:
layout2 = BoxLayout(orientation='horizontal')
name = item['nama']
email = item['email']
label = Label(text=name)
label2 = Label(text=email)
layout2.add_widget(label)
layout2.add_widget(label2)
layout.add_widget(layout2)
self.add_widget(layout)
headers = {
'Authorization': 'Basic ' + ('%s:%s' % (
'admin', '1234')).encode('base-64'),
'Accept': '*/*',
}
UrlRequest('http://localhost/tutorial/demo/tamu_api/tamus.json', req_headers=headers, on_success=on_success)
class Demo(App):
def build(self):
return Example()
if __name__ == '__main__':
Demo().run()
@CoutinhoElias
Copy link

Can you show your rest code too?

@Cheaterman
Copy link

Python2? :-)
str.encode('base-64') on Python3 raises LookupError: 'base-64' is not a text encoding; use codecs.encode() to handle arbitrary codecs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment