Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
API Calaos - Recuperer le JSON avec Python 3
#3
Merci Raoul.

Donc voila comment faire pour ceux que ca interesse.

Code:
import urllib.request, urllib.parse
import json
import ssl

calaos_url = 'https://XXX.XXX.XXX.XXX/api.php' # Calaos server API url
calaos_user = 'XXX'
calaos_password = 'XXX'

# Parameters dictionary to be sent to Calaos server
dict_send = {
    'cn_user': calaos_user,
    'cn_pass': calaos_password,
    'action': 'get_home'  # get the complete configuration of the house
    }

json_send = json.dumps(dict_send) # parameters string in JSON format
data_send = json_send.encode('ascii') # bytes data to be sent
headers_send = {'Content-Type': 'application/json'} # media type of the data to be sent
request = urllib.request.Request(calaos_url, data_send, headers_send) # data sent with POST method
context = ssl._create_unverified_context() # do not verify the SSL certificate

with urllib.request.urlopen(request, context=context) as response:
    print(response.info())
    data_receive = response.read() # bytes data received
    json_receive = data_receive.decode('ascii') # string received in JSON format
    dict_receive = json.loads(json_receive) # dictionary received
    print(dict_receive)

EDIT : C'est maintenant sur le wiki https://calaos.fr/wiki/en/protocole_json..._languages
  calaos-os-raspberrypi2-v3.0-alpha6-14-g341535a-2021-01-17 on Raspberry Pi 2 ▶ Wago_2.2/wago_881.pro on Wago 750-881 ▶ DS18B20 sensors on Pi GPIO ▶ Node-RED









Reply


Messages In This Thread
RE: API Calaos - Recuperer le JSON avec Python 3 - by mifrey - 07-27-2016, 10:48 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)