Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Index out of range #29

Closed
b0ne opened this issue Dec 3, 2018 · 9 comments
Closed

Index out of range #29

b0ne opened this issue Dec 3, 2018 · 9 comments

Comments

@b0ne
Copy link

b0ne commented Dec 3, 2018

Describe the bug
Error when trying to get the data from HydroQuebec

To Reproduce
The command pyhydroquebec -u username -p password (-j and witouth -j) return an error

Task exception was never retrieved
future: <Task finished coro=<HydroQuebecClient.fetch_data() done, defined at /usr/local/lib/python3.5/dist-packages/pyhydroquebec/client.py:388> exception=IndexError('list index out of range',)>
Traceback (most recent call last):
File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
File "/usr/local/lib/python3.5/dist-packages/pyhydroquebec/client.py", line 415, in fetch_data
hourly_data = yield from self._get_hourly_data(day_date, p_p_id)
File "/usr/local/lib/python3.5/dist-packages/pyhydroquebec/client.py", line 334, in _get_hourly_data
hourly_weather_data = json_output['results'][0]['listeTemperaturesHeure']
IndexError: list index out of range

Seem linked to the fact that HydroQuebec dosn't register all the data yesterday

image

@b0ne
Copy link
Author

b0ne commented Dec 3, 2018

@titilambert

Hi, I looked the code at the line 334 and it seem to try to get the value at position 0 of the array Json_Ouput['result'] and then get an error because the array seem to be empty. I modified the code to add a verification that the length of the arrary is >1 and if not then to do the same thing if the temperature data was missing.

if not json_output.get('results'):
# Missing Temperature data from Hydro-Quebec (but don't crash the app for that)
hourly_weather_data = [None]*24
elif len(json_ouput['results'])<1:
# Data from Hydro-Quebec isn't good (but don't crash the app for that)
hourly_weather_data = [None]*24
else:
hourly_weather_data = json_output['results'][0]['listeTemperaturesHeure'] <

It seem to work for me!

@titilambert
Copy link
Owner

This issue seems already fixed, see here: https://github.com/titilambert/pyhydroquebec/blob/master/pyhydroquebec/client.py#L341
Could you try with the 2.4.0 ?

@b0ne
Copy link
Author

b0ne commented Dec 4, 2018

I can confirm the the code you just linked dosn't work (event in 2.4.0).
I added en else if if you look at the code I quoted!

You look if you get a result, but not if the result contain any data, for some rease the temperature was n/d today so the program got an array but an array of size 0 so when he try to look for the data at position 0 its throwing an out of bound.

@titilambert
Copy link
Owner

titilambert commented Dec 4, 2018

I really don't understand your patch :/ The issue should be handled by

if not json_output.get('results'):

This is really strange...

Could you add :

print(json_output):

To see the value of the variable ?

Thanks !

@b0ne
Copy link
Author

b0ne commented Dec 4, 2018

The
if not json_output.get('results')
work if its returning None, but if it returning an empty array it will pass

@titilambert
Copy link
Owner

I'm really not sure of that.
Could you try this command line ?

python3 -c "print('EMPTY') if not [] else print('NOT EMPTY')"

@b0ne
Copy link
Author

b0ne commented Dec 4, 2018

python3 -c "print('EMPTY') if not [] else print('NOT EMPTY')"

EMPTY

@b0ne
Copy link
Author

b0ne commented Dec 4, 2018

Here the print value : {'success': True, 'results': []}

So in this case i think the
if not json_output.get('results')

Get the result from sucess : true and not the result []

@titilambert
Copy link
Owner

I'm closing this issue because of the Hydroquebec update see #35

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants