xperimental / netatmo-exporter

Prometheus exporter for Netatmo sensor data.
MIT License
44 stars 18 forks source link

Error creating client: oauth2: cannot fetch token: 400\nResponse: {\"error\":\"invalid_client\"} #25

Closed QuiiBz closed 1 year ago

QuiiBz commented 2 years ago

Hi, I have an error when running this exporter. I created an app in Netatmo developer portal, copied the client and secret id, and copied my username and password and I still get this "invalid_client" error.

The credentials are the right ones, I checked multiple times. I also tried to create another app and activate/deactivate the app, but still had the same error.

Here's the full docker-compose service:

netatmo-exporter:
  image: xperimental/netatmo-exporter
  container_name: netatmo-exporter
  restart: unless-stopped
  ports:
    - 9210:9210
  environment:
    - NETATMO_CLIENT_ID='clientid'
    - NETATMO_CLIENT_SECRET='clientsecret'
    - NETATMO_CLIENT_USERNAME='username'
    - NETATMO_CLIENT_PASSWORD='password'
  networks:
    - proxy
QuiiBz commented 2 years ago

Found a solution by using command instead of environment, it seems like the environment variables are not working:

command:
  - '-i'
  - 'clientid'
  - '-s'
  - 'clientsecret
  - '-u'
  - 'username'
  - '-p'
  - 'password'
xperimental commented 2 years ago

I can't reproduce the issue. I have the netatmo-exporter running locally in a Docker container configured using environment variables and it works fine.

Even with your configuration copy&pasted it seems to pick up the configuration parameters fine.

Could you check which version of the netatmo-exporter you are using? Maybe it's an old image.

hexa2k9 commented 2 years ago

I'm experiencing the same.

However for me no workarounds work. I've tried settings in environment, in env_file or as command. I receive with all attempts the same error.

I've reset client id/client secret & changed my Netatmo Password, still no luck.

It worked for a couple of days (eg Sunday until today morning) but things went stopped working shortly after the raspberry pi crashed the exporter was running on as a Docker Compose based Container.

Version running here is 1.4.0 from ghcr.io (tested with latest too).

Same thing happens when going with the Binaries provided as Releases (which are named incorrectly as it isn't really a "bz2" archive):

# ./netatmo-exporter-1.4.0-arm64.bz2 -i <client-id> -s <client-secret> -u <email> -p <password>
INFO Login as <email>
FATA Error creating client: oauth2: cannot fetch token: 400
Response: {"error":"invalid_client"}
hexa2k9 commented 2 years ago

I found - at least for me - the fix. And it's stupid.

The Application on Netatmo Developer Portal got disabled for some reason. I cannot really tell why this happened - changes don't seem to be exposed to that level - but after enabling it again things are just fine.

xperimental commented 2 years ago

which are named incorrectly as it isn't really a "bz2" archive

Checked that yesterday and the arm64 binary really was not compressed. This is fixed now.


I'm inclined to close this issue. For me, it looks like both occurrences were just wrong credentials.

QuiiBz commented 2 years ago

My initial issue wasn't due to wrong credentials, as moving from environment to command resolved the issue.

I don't have the bandwidth right now to check the version of the Docker image I was using, but I always use the latest available. Also, it's running on a Raspberry PI (so arm64).

xperimental commented 2 years ago

@QuiiBz I can keep it open, but like already commented, I was not able to reproduce the issue you had with the exporter not being able to read the values from environment. Your use-case of using Docker on arm64 is close to my own, so I wondered if maybe the version would be different.

QuiiBz commented 2 years ago

Here's the id of the image I have locally: 83db35395031

xperimental commented 2 years ago

@QuiiBz Could you look for the "digest" of the image instead? It's part of the output when you do docker inspect <imagename/id>

QuiiBz commented 2 years ago

I think its this part?

"RepoDigests": [
  "xperimental/netatmo-exporter@sha256:7ee132fff9d19b91084a21ac6347d563ceb72358a26f81b4d9fe4009d8d2f4c7"
],
xperimental commented 2 years ago

@QuiiBz I have tested with the image you posted and did not find an issue in the exporter picking up the environment variables.

Looking at your docker-compose.yml again I had an idea, though: I always assumed the single-quotes around the values were just for demonstrating which value you put there. But if you actually put single-quotes around the values in the docker-compose file then these quotes will be passed on with the value as there is no quoting needed in the file. And if the exporter then tries to use 'value' instead of value for authentication this will lead to an error.

Is this maybe what happened?

xperimental commented 1 year ago

@QuiiBz Have you checked the idea from the last comment and can confirm that this was the original issue?

QuiiBz commented 1 year ago

I’ll be back home in a week and will verify this, but it seems plausible.

xperimental commented 1 year ago

@QuiiBz Any update on this?

QuiiBz commented 1 year ago

Thanks for the reminder. After removing the quotes, it seems like it's working fine!