Error: List index out of range whit ubidots json dict



  • Hello! Im trying to get a varible from ubidots on omega2, this variable is a json dict and the values are 1 or 0 (its a switch). When a start the code remind me list index out of range error.

    Error: File "main.py", line 23 in main if tapparellasu[0]['value']: IndexError: list index out of range

    The output of: print (tapparellasu) is [] and the output of print TapparellaSu is the name of the Ubidots variable (and so the program can get the ubidots variable but i can read the value from the dict.)

    i've just talk whit ubidots support and if i run the script on the pc i've no one problem, but on omega 2 still not working.
    Im using ubidots 1.6.6 python client code found on GitHub, whit python 2.7. i've not idea about where is the problem or how fix it..

    The code:

    import os
    import json
    import onionGpio
    import time
    import ubidots
    from ubidots import ApiClient
    api = ApiClient(token='wefwfwfwefwefwefwefrwgewrgerfgwef')
    gpio6 = onionGpio.OnionGpio(6)
    gpio7 = onionGpio.OnionGpio(7)
    tapparellasu = 0
    status = gpio6.setOutputDirection(0)
    status = gpio7.setOutputDirection(0)

    def main():
    TapparellaSu = api.get_variable('uywqegfuywefkwaeuiyfyuwefjukghwef')
    tapparellasu = TapparellaSu.get_values(1)
    if tapparellasu[0]['value']:
    status = gpio6.setValue(1)
    else:
    status = gpio6.setValue(0)
    print tapparellasu[0]['value']
    time.sleep(1)
    if name == 'main':
    main()

    Thanks for your help!
    Ps: (sorry for my bad english :( )



Looks like your connection to Onion Community was lost, please wait while we try to reconnect.