wxt9861 / ynab

YNAB component for Home Assistant
MIT License
50 stars 20 forks source link

Could not retrieve data - verify API key #1

Closed kajhoej closed 4 years ago

kajhoej commented 5 years ago

I'm trying to get your fine integration to work, but I keep getting this error in my logs.

I have verified that I have a correct API Key for ynab. I have some automations i Node-red which uses the ynab API so I know the API keys are working.

I'm using version 0.1.3 from HACS

My config configuration.yaml looks like this

ynab:
  api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The only thing the logs say are:

2019-11-07 23:30:48 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.ynab
2019-11-07 23:30:49 ERROR (MainThread) [custom_components.ynab] Could not retrieve data - verify API key
wxt9861 commented 4 years ago

Hi.

Do you also get the same error if you specify a budget id?

ynab:
  api_key: <api_key_here>
  budget: <budget_id_here>

I will also take a look at adding better debug logging in the next few days so these types of issues are easier to troubleshoot.

kajhoej commented 4 years ago

Yes, No difference adding the budget id.

wxt9861 commented 4 years ago

I am unable to reproduce the error unless I enter a wrong API key. Unfortunately, the python package used for this component does not provide much information about the connection it makes, so if the API key is correct, its a guessing game of what else it can be.

There is another API available for YNAB which looks more capable and I might just have to rewrite the component to use that.

The only other thing, when you enter the API key, do you put it in quotes or without? I haven't tested it (will tomorrow) and don't think it would matter, but worth a check.

Like this?


ynab:
  api_key: "my_api_key_here"
kajhoej commented 4 years ago

I tried with "" around the api_key as you suggested but no change.

On my laptop I installed python3.7 and the ynab-api you use and tried a small test program that was shown in their README.md file.

from ynab_sdk import YNAB

ynab = YNAB('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
print(ynab.budgets.get_budgets())

This works fine. So very strange.

More info about my instsallation in case its needed:

arch x86_64
dev false
docker true
hassio true
os_name Linux
python_version 3.7.4
timezone Europe/Copenhagen
version 0.100.3
virtualenv false
wxt9861 commented 4 years ago

Strange indeed. The sucky thing is the API doesn't provide connection details, it throws a generic error. I looked at using another API, but it does not support python3.7 at this time.

Back to the drawing board, I just need to figure out how to replicate the error - the only way I can do it now is by entering a wrong API key, but thats not the issue here.

wxt9861 commented 4 years ago

Can you please try release v0.1.4? i added a function to check if HASS can communicate with YNAB API endpoint. This will at least verify we are able to establish a connection before API key gets involved.

Successful result will be displayed if you have debugging enabled Failed results will be displayed as an error

kajhoej commented 4 years ago

I have upgraded to v0.1.4 and have snipped the following the log:

2019-11-13 21:06:33 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for ynab which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
...
2019-11-13 21:06:34 INFO (MainThread) [homeassistant.setup] Setting up ynab
2019-11-13 21:06:34 INFO (MainThread) [custom_components.ynab] 
-------------------------------------------------------------------
ynab
Version: 0.1.4
This is a custom component
If you have any issues with this you need to open an issue here:
https://github.com/wxt9861/ynab/issues
-------------------------------------------------------------------

2019-11-13 21:06:34 DEBUG (MainThread) [custom_components.ynab] Connection with YNAB established
2019-11-13 21:06:34 DEBUG (MainThread) [custom_components.ynab] Using budget - last-used
2019-11-13 21:06:34 DEBUG (MainThread) [custom_components.ynab] Monitoring categories - []
2019-11-13 21:06:34 INFO (MainThread) [homeassistant.setup] Setup of domain ynab took 0.5 seconds.
...
2019-11-13 21:06:49 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.ynab
...
2019-11-13 21:06:50 ERROR (MainThread) [custom_components.ynab] Could not retrieve data - verify API key 
...
2019-11-13 21:11:57 ERROR (MainThread) [custom_components.ynab] Could not retrieve data - verify API key 
...
2019-11-13 21:17:04 ERROR (MainThread) [custom_components.ynab] Could not retrieve data - verify API key 
...
quinnhosler commented 4 years ago

I just took a moment to look into this, and it appears the problem is within the ynab_sdk component itself.

I submitted a pull request on the original repository. I don't know how long this takes to make it to the pip install, but the changes can be made manually. They're very minor.

Find changes here.

burnnat commented 4 years ago

@quinnhosler Thanks for the patch, I applied the changes manually in my site-packages and that solved the issue for me. I didn't see any open PR here, am I looking at the right repo? Would be nice to get a published version so I don't have to worry about losing the changes.

quinnhosler commented 4 years ago

Definitely thought I had opened a PR. I went ahead and opened one; hopefully it'll be merged sooner than later.

Glad the changes worked for you!

burnnat commented 4 years ago

Looks like ynab-sdk 0.0.4 was published including the parser fix! @wxt9861, any chance for a new version with the updated dependency?

akcamperdude commented 4 years ago

I'm seeing the same issue on the latest release...no info except that the token doesn't work. Even created a new token and doesn't work. api_key is the only option I'm specifying in my config. I have a couple older budgets but specifying one doesn't seem to make a difference.

Logger: custom_components.ynab Source: custom_components/ynab/init.py:209 Integration: ynab (documentation) First occurred: 3:37:14 PM (1 occurrences) Last logged: 3:37:14 PM

Could not retrieve data - verify API key