andrew-blake / britishgas_myenergy_client

British Gas My Energy Client - download smart meter usage data
MIT License
13 stars 6 forks source link

Commiting changes to work under python 3.4 and work with latest API #2

Closed tinoest closed 7 years ago

tinoest commented 7 years ago

Changed to talk with the latest Apple Client API and updated to work under python3.4

tinoest commented 7 years ago

Fixes #1

andrew-blake commented 7 years ago

Running this patch on Python 2.7 gives an error

  File "./download-usage.py", line 6, in <module>
    from britishgas_myenergy_client import MyEnergyClient
  File "/data/britishgas_myenergy_client/britishgas_myenergy_client.py", line 1, in <module>
    import print_function
ImportError: No module named print_function

Changing to

from __future__ import print_function

seems to fix that, but they I observe the exception mentioned in https://github.com/andrew-blake/britishgas_myenergy_client/issues/1

$ ./download-usage.py
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/data/britishgas_myenergy_client/download-usage.py in <module>()
      6 from britishgas_myenergy_client import MyEnergyClient
      7
----> 8 client = MyEnergyClient(username=USERNAME, password=PASSWORD, proxies=PROXIES, debug=DEBUG, ssl_verify=SSL_VERIFY)
      9
     10 today = date.today()

/data/britishgas_myenergy_client/britishgas_myenergy_client.py in __init__(self, username, password, proxies, debug, ssl_verify)
     63         self.is_initialised = False
     64
---> 65         self._login()
     66
     67     def _unixtime_in_ms(self):

/data/britishgas_myenergy_client/britishgas_myenergy_client.py in _login(self)
    127         self.response = json.loads(req1.content.decode())
    128         self.is_authenticated = self.response['OAMAuthenticate']['isAuthenticated'] == u'TRUE'
--> 129         self.account_number = self.response['OAMAuthenticate']['Accounts'][0]['AccountNumber']
    130         self.ucrn = self.response['OAMAuthenticate']['Accounts'][0]['CustomerDetails']['Ucrn']
    131

KeyError: 'Accounts'
tinoest commented 7 years ago

I didn't test it under python 2.7 as I don't have that installed im afraid.

It ran ok and downloaded all the content under 3.4 ok for me.

I was getting the account error when I used the wrong password/login credentials

andrew-blake commented 7 years ago

Yes, using the right password helps.