gchenuet / nest-datagraph

Nest thermostat dashboard and graph charts
MIT License
36 stars 17 forks source link

ConfigParser issue when using poller.py #33

Closed sebastientinel closed 5 years ago

sebastientinel commented 6 years ago

Hi,

I used to run an old version of Nest Datagraph (thank you very much by the way) without configparser. I just did a clone of the repository (in a new directory) in order to update my installation.

When I tried to run poller.py, I've got issue bellow :

[root@lab nest-datagraph]# /usr/bin/python /opt/nest-datagraph/backend/poller.py
ConfigParser instance has no attribute '__getitem__'

It seems it could be due to a syntax issue regarding python2 and python3. Indeed, the syntax used in poller.py seems to be intended to run with python3. Altough, nest.py is developed to use python2.

Maybe something is wrong in my environment.

Please find bellow the details of my environment :

[root@lab nest-datagraph]# cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core)

[root@lab nest-datagraph]# uname -a
Linux 4.4.6-std-2 #1 SMP Mon Mar 21 13:41:00 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

[root@lab nest-datagraph]# python -V
Python 2.7.5

[root@lab nest-datagraph]# pip -V
pip 18.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)

[root@lab nest-datagraph]# pip install -r setup/requirements.txt
Requirement already satisfied: datetime in /usr/lib64/python2.7/site-packages (from -r setup/requirements.txt (line 1)) (4.3)
Requirement already satisfied: mysql-connector-python in /usr/lib/python2.7/site-packages (from -r setup/requirements.txt (line 2)) (2.1.7)
Requirement already satisfied: pyowm in /usr/lib/python2.7/site-packages (from -r setup/requirements.txt (line 3)) (2.7.1)
Requirement already satisfied: configparser in /usr/lib/python2.7/site-packages (from -r setup/requirements.txt (line 4)) (3.5.0)
Requirement already satisfied: zope.interface in /usr/lib64/python2.7/site-packages (from datetime->-r setup/requirements.txt (line 1)) (4.0.5)
Requirement already satisfied: pytz in /usr/lib/python2.7/site-packages (from datetime->-r setup/requirements.txt (line 1)) (2016.10)
Requirement already satisfied: setuptools in /usr/lib/python2.7/site-packages (from zope.interface->datetime->-r setup/requirements.txt (line 1)) (0.9.8)

[root@lab nest-datagraph]# pip list | grep configparser
configparser                     3.5.0

Thank you for your help/inputs

sebastientinel commented 6 years ago

I confirm the issue is due to the use of python2.

Here is a test by changing the use of ConfigParser object following Python 2 doc (opposed to Python 3 doc) :

c = configparser.ConfigParser()
c.read(os.path.join(os.path.abspath(os.path.dirname(__file__)),
                    '../frontend/conf',
                    'settings.ini'))

# Python 2
test = c.get('nest', 'nest_index')
print(test)

# Python 3
test2 = c['nest']['nest_index']
print(test2)

Here is the result :

[root@lab backend]# python test.py
0
Traceback (most recent call last):
  File "test.py", line 32, in <module>
    test2 = c['nest']['nest_index']
AttributeError: ConfigParser instance has no attribute '__getitem__'

So is the code supposed to run in Python 3 ? If it is the case, nest.py need to be converted for Python 3.

Thank you for you feedback/help. If needed I can provide some help.

gchenuet commented 5 years ago

I haven't time (and Nest Thermostat) to maintain this project. Feel free to open a PR to fix it :)

Thanks.