Created
April 3, 2013 11:52
-
-
Save rohman/5300550 to your computer and use it in GitHub Desktop.
Sample Rest With Kivy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python2? :-)
str.encode('base-64')
on Python3 raisesLookupError: 'base-64' is not a text encoding; use codecs.encode() to handle arbitrary codecs