python source asked to refresh authentification

ni_hao_1

I'm forced to use python 2.7.
With some help from Leslie (community manager) I am able to download the netatmo (stations) data.
I want to automate the authenfication (every 3hrs) by using my refresh_token in python.

Who can give me that source in python ?

I tried the code below, but got the error: {"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"}...

import requests

url = 'https://api.netatmo.com/oauth2/token'
payload = {
        "client_id": "xxxxxxx",
        "client_secret": "xxxxxx",
        "grant_type":"refresh_token",
        "refresh_token":"xxxxxx"
        }
response = requests.request("POST", url, params=payload)
print(response.text.encode('utf8'))

0

Comments

5 comments

  • Comment author
    lars

    I have used this a lot. Works great.

    https://github.com/philippelt/netatmo-api-python

    0
  • Comment author
    ni_hao_1

    Thanks Lars, but does not work with python 2.7. Therefor I started explicit by mentioning which python I have to use. Besides I have been in contact with Philippe, the author of the sources in your hyperlink. Philippe does not have a python 2.x platform and is about to stop supporting python 2.x. I tried that github source but too many errors. 

     

    So my question still remains: Who can give me that source in python ? (and the word 'that' is referring to python 2.7)

    0
  • Comment author
    lschiltz0123
    • Edited

    Hi ni_hao_1,

    I use the python version : 2.7.16 and modified the old script to access to my camera in order to change the refresh token at each access request and save it into a file.

    Is THAT what you're expecting?

     

    0
  • Comment author
    ni_hao_1

    lschiltz0123, yes exactly. Will ya please give me your new script?

    0
  • Comment author
    ni_hao_1
    • Edited

    In the meanwhile I find out that my first posted code is ok. The only thing was and is, that when my refresh token has been expired after 3 hours the above mentiones code does not work (error 400 because my refresh code is invalid). I have to goto the dev website and manually have to genereate new tokens (access and refresh), put it in my python datafile and then everything works fine. So my question is: how can I automate (in python 2.7) to generate both new tokens or who has a kind of converter which will generate (24/7) new tokens after every 2 hours and 50 minutes

    0

Please sign in to leave a comment.