IndexError: list index out of range

Hello Everyone,

I was developing an application using the lifx bulbs last month, and I hadn’t worked on it for the last 4 weeks. Today, I was going to work on it again and continue from the place I stopped. Now, I cant access to the lifx bulb using python API, I always have the same error. The code is simple as the following:

import sys
from lifxlan import LifxLAN
lifx=LifxLAN ()
devices=lifx.get_lights()
bulb=devices[0]
then suddenly I have this error :

Traceback (most recent call last):
File “C:\Users\pc gaming\Desktop\CB.py”, line 10, in
bulb=devices[0]
IndexError: list index out of range

I am not that deep in python language, any suggestions for solving this issue :frowning: ?

Thank you in advance

So I haven’t received my bulbs yet, so I don’t have the ability to test this, but I do know python. What this is saying is that when you get the lights, the list is empty (there is no index zero). It could be that your connectivity is having issues, so you might want to check that first :slight_smile:

Thank you, I appreciate your try, but I already tried multiple Bulbs with direct and undirect comunication, and all failed. Same error everytime :sob:

My bulbs should be here middle of next week and I can poke around with your code. If you’re having issues still, then, let me know and I’ll happily poke at it :slight_smile:

1 Like

Thank you, appreciated !

The answer is in your error.

IndexError: list index out of range

bulb=devices[0] this line tries to access the first item however you have not confirmed if there is any and you have not confirmed the contents of the bulb object.

try printing the bulb object out you need to convert it to a string of course but this might help you to understand what is going on.

Your error is you are trying to access something that isn’t there.

I used this.
from lifxlan import LifxLAN
lifx=LifxLAN ()
devices=lifx.get_lights()
print("devices = " + str(devices))

This results in
devices = [<lifxlan.light.Light object at 0x0000000004483D68>, <lifxlan.light.Light object at 0x0000000004483DD8>, <lifxlan.light.Light object at 0x0000000004483E48>, <lifxlan.light.Light object at 0x0000000004483CC0>, <lifxlan.light.Light object at 0x0000000004483EF0>, <lifxlan.multizonelight.MultiZoneLight object at 0x0000000004483F98>]

As you can see it is another object so this would point to your not having found any bulbs on your network.

Use the hello world example first to confirm you are seeing bulbs then you can work on your script using that as an example.