kershner / screenBloom

Fake Ambilight for Philips Hue via Python
http://www.screenbloom.com
329 stars 48 forks source link

Error code #1

Closed Spu00Key closed 8 years ago

Spu00Key commented 8 years ago

First time user. Got this after setting up my username and connecting to the bridge.

Traceback (most recent call last):
  File "c:\python27\lib\site-packages\flask\app.py", line 1836, in __call__

  File "c:\python27\lib\site-packages\flask\app.py", line 1820, in wsgi_app

  File "c:\python27\lib\site-packages\flask\app.py", line 1403, in handle_exception

  File "c:\python27\lib\site-packages\flask\app.py", line 1817, in wsgi_app

  File "c:\python27\lib\site-packages\flask\app.py", line 1477, in full_dispatch_request

  File "c:\python27\lib\site-packages\flask\app.py", line 1381, in handle_user_exception

  File "c:\python27\lib\site-packages\flask\app.py", line 1475, in full_dispatch_request

  File "c:\python27\lib\site-packages\flask\app.py", line 1461, in dispatch_request

  File "ScreenBloom.py", line 42, in index

  File "c:\programming\projects\hue_project\app\modules\screenbloom_functions.py", line 167, in get_lights_data

TypeError: list indices must be integers, not str
kershner commented 8 years ago

Seem to recall running into this before, I'm looking into it. Can you maybe paste your config.cfg file? In any case if you delete that and re-run the program/startup sequence it'll gen a new one for you and might solve the issue.

Spu00Key commented 8 years ago

I've done the default install and had to run it as admin due to access - same error I've installed it into a folder that everyone has write access - same error Both config files looked the same.

The IP matches my bridge, the number of lights matched as well.

hue_ip = 192.168.1.212
username = MaddBomber83

[Light Settings]
all_lights = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
active = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
update = 12
bri = 254
default = 200,200,200

[Dynamic Brightness]
running = 0
min_bri = 125

[Party Mode]
running = 0

[App State]
running = 0
user_exit = 0
kershner commented 8 years ago

I'm somewhat able to reproduce the error on my end, but I don't have access to all the data since I don't have 24 lights for my bridge to ping, so I'm not able to fully test it. Are other Hue apps able to detect and interact with all 24 of your lights? Seems like there might be some bad/inconsistent data somewhere in one of those light's JSON and Python isn't able to interpret it.

You could try cutting out numbers from your all_lights/active_lights settings until you find the culprit light.

Spu00Key commented 8 years ago

I'll do some testing with that later tonight (hopefully). Android (Philips Hue, SmartHome, Hue Pro, Hue Maniace) and Windows (WinHue3) are able to handle all of the lights.

On Tue, Mar 15, 2016 at 8:00 PM Tyler Kershner notifications@github.com wrote:

I'm somewhat able to reproduce the error on my end, but I don't have access to all the data since I don't have 24 lights for my bridge to ping, so I'm not able to fully test it. Are other Hue apps able to detect and interact with all 24 of your lights? Seems like there might be some bad/inconsistent data somewhere in one of those light's JSON and Python isn't able to interpret it.

You could try cutting out numbers from your _alllights/_activelights settings until you find the culprit light.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/kershner/screenBloom/issues/1#issuecomment-197128483

TwanoO67 commented 8 years ago

Same error here. First time user too. I have fewer device on my hue network ( 2 white bulb, 1 color strip, 1 bloom and 1 lightify plug) My config.cfg look exactly the same (~ except different ip/name and just 5 bulb, all active)

I would be glad to debug it myself, but I'm unable to run the project cloned from github (maybe some missing dependencies ?)

kershner commented 8 years ago

If you'd like to take a crack at debugging this I'd be very grateful as I haven't been able to solve the issue on my end. This will be a bit annoying because I'm updating the app and it's currently in an unfinished state at the most recent commit.

You'll need to checkout commit ad71cbb after you clone. Python dependencies required are just flask, pillow, requests, and beautifulhue.

In the app/modules folder, you'll need to create an init.py file.
I've created a 7zip archive of the additional dependencies you'll need to place in the app/modules and app/static folders, you can grab that from here: http://www.kershner.org/static/distribute/sb_dependencies.zip

The final step is to fix the template paths that are expecting the compiled references. In app/screenbloom.py, uncomment line 8, and comment out line 9. This will allow the app to find the templates folder.

Let me know if you run into any issues and thanks again for your help!

Edit

Pushed out a new version. Should make things a bit easier as it's cleaner all around. New compiled .exe at the main website.

TwanoO67 commented 8 years ago

Hi Tyler,

I just tried both mac and win executable on my network and neither did work.

on windows: the installation and configuration of the hub did work, but after that the app just respond error 500, but no error logging in the cmd part.

on mac, the script doesn't run, having the issues: File "ExtensionLoader_PIL__imaging.py", line 14, in bootstrap ImportError: dlopen(/Users/TwanoO/Downloads/screenBloom/screenBloom/PIL._imaging.so, 2): Library not loaded: /usr/local/opt/libtiff/lib/libtiff.5.dylib Referenced from: /Users/TwanoO/Downloads/screenBloom/screenBloom/PIL._imaging.so Reason: image not found

Also tried your manual method, but the dependencies pack isn't available anymore. Could you re-upload it?

kershner commented 8 years ago

Very strange that the Windows install didn't work. Try running ScreenBloom as an admin, I know sometimes it has permissions issues. The Mac build is brand new and has been tested on exactly 2 machines (mine and my girlfriend's) so it's understandable that that one might need some work.

Which file did you run (for the Mac version)? I recommend ignoring the .app package and just running the ScreenBloom exec file directly from inside the included directory.

The dependencies are back up at http://www.kershner.org/static/distribute/sb_dependencies.zip.

Let me know if there's anything else you need

Spu00Key commented 8 years ago

I redownloaded and installed into a non protected directory. It now works just fine!

Now I just need to figure out how to decrease the brightness and increase saturation. ;)

Spu00Key commented 8 years ago

I should also note that I no longer have Python installed.

kershner commented 8 years ago

That's great news, glad to hear it. I simplified the options regarding brightness to just be a 'minimum-brightness' slider, which means the value you set is the lowest brightness your Hues will get while ScreenBloom is running. I haven't even messed with saturation settings, that could yield some interesting results!

Anyway the codebase is pretty small so if you wanna try and add some saturation stuff, go for it and let me know how it goes!

Spu00Key commented 8 years ago

I will have to take a look. I've been tweaking around with https://github.com/Blodjer/HueImmersive for a bit, so I have some of the basic formulas to work with. Also following https://sourceforge.net/projects/winhue/ to see about plugins. No formal training, but keeps me going in a direction ;).

It seems others are still having issues? So I'm assuming I should not close.

kershner commented 8 years ago

Yeah go ahead and leave it open for now. I'm thinking TwanO's original issue is a permissions thing, so hopefully we can close it out soon enough. Thanks for all your help.

TwanoO67 commented 8 years ago

On Windows: I tried a full uninstall / reinstall using admin rights, but I'm still stuck on the same issue. Installation works fine, detection in automatic doesn't works, but the manual configuration of the hub's ip is working. After that I'm stuck having error 500 on every page

On mac, I tried the exec file in the included folder And the github version with your dépendencies pack, both are stuck on the "no image found" that seems to come from PIL.

Edit: Just tried with my office mac, on OS X 10.11.2, the downloadable app is working (without any hub at the office...). Maybe my issues at home are related to my existing python and modules installation... I will take further look at that and keep you posted.

kershner commented 8 years ago

For the Windows attempt - when you get the 500, Flask should be spitting out a bunch of stuff in the Python console window, but you're saying it's not? Is there anything going on there at all? Also, when you hit the 500 error can you check the JavaScript console and see if that's saying anything?

EDIT - regarding your Mac issue, I had a lot of problems building the Mac version because of errors like what you were seeing (PIL dependency images not being found etc). The issue ended up being related to the Python/dependencies version on my system. I used the Homebrew versions and everything seemed to work, so take that info however ya like.

Another EDIT - Just heard from another user that is getting a 500 on register so I think this might just be something dumb I forgot. I'll crack into it as soon as I can and hopefully push out a fix this weekend. Thanks for the patience.

TwanoO67 commented 8 years ago

Just tried with my office mac on my home network, and I got stuck with the same error "list indices must be integers, not str" in screenblom_function line 163. (I don't have manually installed python and/or any dependencies on this computer so fresh install)

EDIT:

I finally got a dev-version working so I can debug manually. So if i pprint the 'result' var in get_light_data function: {'resource': {u'manufacturername': u'Philips', u'modelid': u'LWB006', u'name': u'Salon 1', u'state': {u'alert': u'none', u'bri': 254, u'on': True, u'reachable': True}, u'swversion': u'66015095', u'type': u'Dimmable light', u'uniqueid': u'00:17:88:01:10:4d:a4:1d-0b'}} {'resource': [{u'error': {u'address': u'/lights/2', u'description': u'resource, /lights/2, not available', u'type': 3}}]} after that the script crash with "list indices must be integers, not str" in screenblom_function line 163. So I suppose that my /lights/2 is causing the issue.

After that I tried something like that: if isinstance(result, (list,dict)): continue

Then the app launched correctly, but no 'bulbs' are on the web page. And I got the error: File "/Users/aweber/GIT/screenBloom/app/modules/screenbloom_functions.py", line 334, in screen_avg for red, green, blue in pixels: ValueError: too many values to unpack

TwanoO67 commented 8 years ago

Ok, so I sorted out the problem. My hub had 2 lights, that doesn't exist anymore, but still appears in the hub's light indexation. So I have in my automatically generated config.cfg all_lights = 1,2,3,4,5 active = 1,2,3,4,5

But the lights 2 and 3 doesn't exist anymore, so I should have all_lights = 1,2,3,4,5,6,7 active = 1,0,0,4,5,6,7

And i'm skipping the 2 and 3 index in the get_lights_data function

Second problem, in the screen_avg function the pixels list had 4 dimensions so I had to change from "for red, green, blue in pixels" to "for red, green, blue, alpha in pixels:"

Now it's working (but I have raw index skipping in the code..) so maybe we should determine a way to test the content of 'result' in get_lights_data, and if unexpected 'continue'

kershner commented 8 years ago

Hey great job debugging this. I'll definitely implement some kind of handling for non-existent lights.

The ' red, green, blue, alpha in pixels' thing is a discrepancy between the Mac and Windows implementations of ImageGrab.grab() (Pillow) I think. The Mac capture has an extra alpha element, which is actually potentially interesting as far as parsing the image. I haven't checked to see if the Windows one actually has alpha too, maybe it does.

I took the Mac version down from my website for the time being. It's too ghetto right now. I'm going to try to get it packaged up properly before I release it again. If you still want to hack around on it I'd be super grateful and will help with whatever ya need.

EDIT I forgot to ask, how did your Bridge come to have missing lights?

TwanoO67 commented 8 years ago

I think that the "missings lights" comes from associating a light with a dimmer switch with the manual way. It's seems to change the zigbee channel of the light, so it goes out of the hub detection, and when you re-add it to the hub it's like a new light.

EDIT: I forgot to mention that those "missings lights" aren't anymore in my hub's devices list, but there's still a gap in the enumeration of the lights.

kershner commented 8 years ago

I've been making progress as far as packaging the app for Macs.
Try out a new build here: http://www.kershner.org/static/distribute/screenBloom.zip. It'll place an icon in the dock, but no console or menubar (as yet).

This build should fix the permissions and missing library issues - but there is a brand new problem, the .app package version is really slow for some reason. I haven't been able to test enough to determine if it's my home network or what. If you wanna test this build out we'll at least know if it works. I'll keep working on it for sure.

I've also created a branch for the Mac version, just fyi.

kershner commented 8 years ago

The main issue here (unavailable lights causing the app the crash) has been resolved in recent updates, so I'm gonna close this issue. Please feel free to re-open one if you have any further problems. Thanks again for all the input.

TwanoO67 commented 8 years ago

Hi Tyler, Just tried the 1.6 version: It still has problems with the fonction "update-bulbs" when selecting a bulb the app crash. The error is "IndexError: list index out of range" on ScreenBloom.py line 143.

It seems that this is because the config file is not well formed.

In my case, I have 10 lights, and the lights 2 and 3 isn't available anymore (the missings liths we already talk about).

What the automatically generated config file look like, after clicking on the bulb 6: all_lights = 1,2,3,4,5,6,7,8 active = 0,0,0,6,0,0 but this config crash the app

Then I manually updated to that values (to make the app working): all_lights = 1,2,3,4,5,6,7,8,9,10 active = 0,0,0,0,0,6,0,0,0,0

kershner commented 8 years ago

Haha it's such a bummer when you think you've got an issue fixed and it comes back!

So it looks like there was an issue in the initialization function. It was trying to compare the full lights list (including the missing lights) with what you are selecting in the front end, which is just a list of your 'working' lights. So it was trying to find indices in the 'active lights' list that just weren't there.

To fix this I just added an IndexError check, and if it fails then a '0' will be appended to the 'active lights' list. This is the change I made: screenbloom_functions.py -> line 224

I've pushed this fix to the Mac and PC versions and updated the website. Pretty sure this will fix it, but if you could give it a test and let me know that'd be great!

TwanoO67 commented 8 years ago

Just tried a new installation on a Win PC setup. There's no more error on selecting the bulbs, but the lights aren't all detected. In fact the new config.cfg looks exactly the same that before: all_lights = 1,2,3,4,5,6,7,8 active = 0,0,0,6,0,0

kershner commented 8 years ago

Depending on when you downloaded, the config directory has moved. I've moved it to the /APPDATA/roaming directory to get around future permissions issues. Check to see if you have a config.cfg in your APPDATA.

Does the program still function normally in other ways?

TwanoO67 commented 8 years ago

I Think the problem is coming from the get lights list function here: https://github.com/kershner/screenBloom/blame/master/app/modules/screenbloom_functions.py#L130

because I think that lights['resource'] as only 8 members in it, but the last light is numbered 10. So maybe we should seek the max index value, to use as number_of_lights

Edit: I have downloaded the app 10 minutes ago, and I don't have screenbloom in User/AppData/Roaming.

kershner commented 8 years ago

Couple questions: are the correct lights showing up in the Bulbs section of the interface? That is to say, it's all of your working/available lights?

And does a 'fresh' config file have the correct values in it as far as all_lights and a bunch of 0s for active_lights?

TwanoO67 commented 8 years ago

The interface only shows lights 1 4 5 6 7 8 2 and 3 are missing (but it's normal, cause it's the unavailable one) 9 and 10 are missing too (but that one should be here)

And No, I delete the config every time I try a new release of yours, and the last one got me that: all_lights = 1,2,3,4,5,6,7,8 active = 0,0,0,6,0,0

kershner commented 8 years ago

If you still have a dev version available can you print this lights variable and let me know what it is?

Pretty sure I know what the issue is I just need your lights output to verify. get_lights_list is a pretty dumb function, probably hasn't been touched in over a year! It should be storing a list of IDs for the lights, but right now it's just stupidly assuming they're all in order (and available) and using the index of a loop. I'm changing it to store the actual IDs of the lights, which is an easy change. I just need to test for unavailable lights like yours.

TwanoO67 commented 8 years ago

Hello Tyler, Sorry for the late answer...

Here's the pprint for the "ressource" var: {'resource': {u'manufacturername': u'Philips', u'modelid': u'LWB006', u'name': u'Salon 1', u'state': {u'alert': u'none', u'bri': 0, u'on': True, u'reachable': False}, u'swversion': u'5.38.1.15095', u'type': u'Dimmable light', u'uniqueid': u'00:17:88:01:10:4d:a4:1d-0b'}} {'resource': [{u'error': {u'address': u'/lights/2', u'description': u'resource, /lights/2, not available', u'type': 3}}]}

Then the code crash with the error: TypeError: list indices must be integers, not str

So to avoid this error you can test that: isinstance(result['resource'], list)

it would respond true if the ressource is a "missing lights". And in that case, maybe we could insert some king of "mockup" data, to keep the right light index, without been able to use it.

kershner commented 8 years ago

Thanks for the update. So is that the direct output of the lights variable here? I was hoping to be able to just copy+paste your data into my code to get as close to your actual config as possible.

In any case, I think this issue was solved by a recent update. The fix was to construct the all_lights_list from the actual IDs of the lights themselves. This happens here. Previously I was using the indices of a loop which is an imprecise way to do things and lead to this issue.

So, with the list of actual IDs, the type checking here should ensure that you'll never be shown unavailable lights in the UI, so they should not be a concern anymore.

Of course, I'm not really able to test this reliably given my Hue setup, so if you could download the new version and let me know if it installs/works OK for you, that'd be great! As always, thank you very much for helping me test this stuff.

TwanoO67 commented 8 years ago

I think that this should do the trick: https://github.com/TwanoO67/screenBloom/commit/022ea2df2f7b3605d11622060fcd56e552ca984d

kershner commented 8 years ago

Looks like the same thing I ended up doing, just earlier in the chain. I think I'll go ahead and use your solution in a future update, as then I can get rid of the check in get_lights_data which feels a bit cleaner to me.

Do let me know how it goes if you end up downloading the current version.

TwanoO67 commented 8 years ago

Ok, good new is: I just tried with a new install of your last commit / dev version on github, it works well without my suggestion. So, I think that the "1.6" binary I had downloaded wasn't the same/last version.

Maybe we should start using "minor" to specify which binary we are talking about, because I ended up with 3 different "1.6" win exe, and I can't figure out which one was working or not ^^

Btw, I re-tried downloading the current binary for mac os, and the app crash on load with: jinja2.exceptions.TemplateNotFound TemplateNotFound: /new_user.html

So on mac I will keep using the dev version for the moment, which work fine :) [ TLDR: this issue can be closed ^^ ]

kershner commented 8 years ago

Haha sorry about the versions. I've just been re-compiling it without a version bump as these are kinda minor tweaks.

I'll look into that Mac issue, first I've heard of it. I'll close this issue now, thanks for all your help.