Differences
This shows you the differences between two versions of the page.
| — | 
                    en:json_python2 [2017/01/21 14:53] (current) mifrey created  | 
            ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ===== Use the API with Python 2 ===== | ||
| + | [[protocole_json|API]] | ||
| + | ==== Example ==== | ||
| + | <code python json_python2.py> | ||
| + | import urllib2 | ||
| + | import json | ||
| + | calaos_url = ' | ||
| + | calaos_user = ' | ||
| + | calaos_password = ' | ||
| + | |||
| + | # Parameters dictionary to be sent to Calaos server | ||
| + | dict_send = { | ||
| + | 	' | ||
| + | 	' | ||
| + | 	' | ||
| + | } | ||
| + | |||
| + | |||
| + | json_send = json.dumps(dict_send) # parameters string in JSON format | ||
| + | data_send = json_send.encode(' | ||
| + | headers_send = {' | ||
| + | request = urllib2.Request(calaos_url, | ||
| + | response = urllib2.urlopen(request) | ||
| + | print(response.info()) | ||
| + | data_receive = response.read() # bytes data received | ||
| + | json_receive = data_receive.decode(' | ||
| + | dict_receive = json.loads(json_receive) # dictionary received | ||
| + | print(dict_receive) | ||
| + | </ | ||