benknight / hue-alfred-workflow

An Alfred workflow for controlling Philips Hue lights.
367 stars 34 forks source link

No json object could be decoded #43

Closed LETRA closed 3 years ago

LETRA commented 6 years ago

Hi. I have a problem for a few days. I thought an update would fix it, but I see that I am the only one who has reported this problem.

When I start Hue Controller I get the message "no json object could be decoded". I hope you can help out.

Thank you.

captura de pantalla 2018-07-12 a las 22 44 07
brichards commented 5 years ago

I've just encountered this myself in the past week.

@benknight Any ideas where I could begin to look to help debug?

benknight commented 5 years ago

@brichards can you open Alfred Preferences, go to Workflows, select Philips Hue Controller, select the little debug icon in the top right, then trigger the workflow by typing "hue" in Alfred, and copy and paste whatever output occurs in the debug log?

Screen Shot 2019-04-27 at 2 06 26 PM
brichards commented 5 years ago

Well isn't that slick. I remember seeing the bug icon when first knocking around Alfred years ago, then promptly forgot about it, it would seem.

Here's my debug log ``` [2019-04-29 09:59:33][input.scriptfilter] Queuing argument '' [2019-04-29 09:59:34][input.scriptfilter] Script with argument '(null)' finished [2019-04-29 09:59:34][ERROR: input.scriptfilter] Code 1: 09:59:33 workflow.py:2249 DEBUG workflow version: 3.0.0 09:59:33 workflow.py:1657 DEBUG reading settings from /Users/brian/Library/Application Support/Alfred 3/Workflow Data/hue-alfred-workflow/settings.json 09:59:33 workflow.py:2532 DEBUG Update check not due 09:59:33 workflow.py:1884 DEBUG loading cached data: /Users/brian/Library/Caches/com.runningwithcrayons.Alfred-3/Workflow Data/hue-alfred-workflow/__workflow_update_status.cpickle 09:59:33 workflow.py:2462 DEBUG update_data: {u'available': False} 09:59:34 workflow.py:1657 DEBUG reading settings from /Users/brian/Library/Application Support/Alfred 3/Workflow Data/hue-alfred-workflow/settings.json 09:59:34 workflow.py:2267 ERROR No JSON object could be decoded Traceback (most recent call last): File "logic/packages/workflow/workflow.py", line 2260, in run func(self) File "/Users/brian/Dropbox/App Settings/Alfred.alfredpreferences/workflows/user.workflow.25AA811F-202B-4A60-87EC-31D89FC1BBBC/logic/filters.py", line 456, in main items = hue_index_filter.get_items() File "/Users/brian/Dropbox/App Settings/Alfred.alfredpreferences/workflows/user.workflow.25AA811F-202B-4A60-87EC-31D89FC1BBBC/logic/filters.py", line 102, in get_items lights = utils.get_lights() File "logic/utils.py", line 85, in get_lights load_full_state() File "logic/utils.py", line 43, in load_full_state data = r.json() File "logic/packages/requests/models.py", line 643, in json return json.loads(self.text or self.content, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads return _default_decoder.decode(s) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 384, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded 09:59:34 workflow.py:2290 DEBUG workflow finished in 0.159 seconds ```

In my case, the error is triggered when load_full_state() attempts to pull back all the data from the bridge. And this was a problem, I've realized, because my bridge IP changed a week or so back when my entire router cabinet was powered down.

The workflow settings still held the original IP address, which is now a different device, and that device returns a 404 response instead of the JSON object expected by the call to data.json().

Manually altering the IP stored in my hue-alfred-workflow/settings.json file resolved the problem for me. And now I'll know to test this again should the problem resurface.

Perhaps an additional exception check is needed here for these rare occasions when the bridge IP changes? I'm not a python guy, so I'm afraid I can't help with a patch for this one.

benknight commented 5 years ago

@brichards excellent, I agree with your assessment of the issue :D Feel free to submit a pull request, or I can look at this issue some time in the future.

If future readers come across this issue and it's still not resolved, uninstalling and reinstalling the workflow should work in the case that the bridge's IP address changed.

merchako commented 5 years ago

In the meantime, the it's easier to delete (or rename) ~/Library/Application Support/Alfred 3/Workflow Data/hue-alfred-workflow/settings.json than it is to replace the IP address stored. So the brainless approach is:

  1. Rename or delete the settings.json,
  2. Press the sync button on your Hue hub,
  3. Reinitialize hue-alfred-workflow by Alfreding hue + the only option.