Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Access Not Working #7

Closed
akcamperdude opened this issue Jul 18, 2020 · 14 comments
Closed

API Access Not Working #7

akcamperdude opened this issue Jul 18, 2020 · 14 comments

Comments

@akcamperdude
Copy link

I'm seeing the same issue as previously, 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

@cisco187
Copy link

I'm having the same problem. I hope this gets fixed/updated soon!

@RobertChili
Copy link

The same issue.
many update/progress on that?

@wxt9861
Copy link
Owner

wxt9861 commented Feb 12, 2021

Does the token work if you run a curl request manually?

curl -H "Authorization: Bearer <ACCESS_TOKEN>" https://api.youneedabudget.com/v1/budgets

@wxt9861
Copy link
Owner

wxt9861 commented Feb 12, 2021

I just remembered we had this issue previously and it was due to a dependency package. I see they have new version available. I'll bump up dependency tomorrow or so and lets see if it solves the problem.

@lndnbrg
Copy link

lndnbrg commented Feb 13, 2021

Hi wxt9861, thanks for this integration! I am having the same issue with "verify API key".

It works when I run the curl request manually. I get a proper JSON response from the API. But in Home Assistant, I get the log message, that the API key is not working.

@wxt9861
Copy link
Owner

wxt9861 commented Feb 17, 2021

Can you test with v0.1.8?

@lndnbrg
Copy link

lndnbrg commented Feb 17, 2021

Have just tested it, but am still receiving the same error message. Is there a way for me to provide some additional debugging info?

wxt9861 added a commit that referenced this issue Feb 19, 2021
wxt9861 added a commit that referenced this issue Feb 19, 2021
@wxt9861
Copy link
Owner

wxt9861 commented Feb 19, 2021

Ok, I cannot replicate unless I intentionally enter a wrong API key. Let's try this, if you can. At the very least, I want to figure out if the issue is coming from the component or the ynab-sdk package it uses to talk to YNAB api.

If you can, get the apitest.py file and run it as a test. All it does is connect to ynab API and shows a summary of budgets. If it works, we know you can successfully connect to ynab and the issue is in this component. If you get an error, than the issue is possibly with the package or elsewhere.

https://github.com/wxt9861/ynab/blob/bug_fix/apitest.py

@lndnbrg
Copy link

lndnbrg commented Feb 19, 2021

Thank you!

This is the export I get from the function (modified):

BudgetSummaryResponse(data=Data(budgets=[Budget(id='00000000-0000-0000-0000-000000000000', name='Family Budget Before Fresh Start on 2016-10-27', last_modified_on=datetime.datetime(2016, 10, 29, 16, 11, 5, tzinfo=tzutc()), first_month='2015-12-01', last_month='2019-03-01', date_format=DateFormat(format='DD.MM.YYYY'), currency_format=CurrencyFormat(iso_code='EUR', example_format='123.456,78', decimal_digits=2, decimal_separator=',', symbol_first=True, group_separator='.', currency_symbol='€', display_symbol=False)), Budget(id='00000000-0000-0000-0000-000000000000', name='Familienbudget (Archived on 2020-01-23)', last_modified_on=datetime.datetime(2020, 9, 18, 13, 23, 45, tzinfo=tzutc()), first_month='2019-10-01', last_month='2020-10-01', date_format=DateFormat(format='DD.MM.YYYY'), currency_format=CurrencyFormat(iso_code='EUR', example_format='123.456,78', decimal_digits=2, decimal_separator=',', symbol_first=True, group_separator='.', currency_symbol='€', display_symbol=False)), Budget(id='00000000-0000-0000-0000-000000000000', name='2016', last_modified_on=datetime.datetime(2016, 10, 29, 16, 11, 26, tzinfo=tzutc()), first_month='2016-10-01', last_month='2019-03-01', date_format=DateFormat(format='DD.MM.YYYY'), currency_format=CurrencyFormat(iso_code='EUR', example_format='123.456,78', decimal_digits=2, decimal_separator=',', symbol_first=True, group_separator='.', currency_symbol='€', display_symbol=False)), Budget(id='00000000-0000-0000-0000-000000000000', name='Family Budget', last_modified_on=datetime.datetime(2018, 5, 8, 7, 18, 57, tzinfo=tzutc()), first_month='2015-12-01', last_month='2019-03-01', date_format=DateFormat(format='DD.MM.YYYY'), currency_format=CurrencyFormat(iso_code='EUR', example_format='123.456,78', decimal_digits=2, decimal_separator=',', symbol_first=True, group_separator='.', currency_symbol='€', display_symbol=False)), Budget(id='00000000-0000-0000-0000-000000000000', name='Lindenberg (Archived on 2017-09-14)', last_modified_on=datetime.datetime(2018, 5, 6, 13, 12, 36, tzinfo=tzutc()), first_month='2017-04-01', last_month='2019-03-01', date_format=DateFormat(format='DD.MM.YYYY'), currency_format=CurrencyFormat(iso_code='EUR', example_format='123.456,78', decimal_digits=2, decimal_separator=',', symbol_first=True, group_separator='.', currency_symbol='€', display_symbol=False)), Budget(id='00000000-0000-0000-0000-000000000000', name='Familienbudget (Archived on 2018-04-02)', last_modified_on=datetime.datetime(2018, 4, 2, 15, 0, 42, tzinfo=tzutc()), first_month='2017-04-01', last_month='2019-03-01', date_format=DateFormat(format='DD.MM.YYYY'), currency_format=CurrencyFormat(iso_code='EUR', example_format='123.456,78', decimal_digits=2, decimal_separator=',', symbol_first=True, group_separator='.', currency_symbol='€', display_symbol=False)), Budget(id='00000000-0000-0000-0000-000000000000', name='Familienbudget (Archived on 2019-09-14)', last_modified_on=datetime.datetime(2019, 11, 11, 19, 48, 21, tzinfo=tzutc()), first_month='2019-01-01', last_month='2019-12-01', date_format=DateFormat(format='DD.MM.YYYY'), currency_format=CurrencyFormat(iso_code='EUR', example_format='123.456,78', decimal_digits=2, decimal_separator=',', symbol_first=True, group_separator='.', currency_symbol='€', display_symbol=False)), Budget(id='00000000-0000-0000-0000-000000000000', name='Lindenberg (Archived on 2017-12-03)', last_modified_on=datetime.datetime(2017, 12, 3, 19, 2, 59, tzinfo=tzutc()), first_month='2017-04-01', last_month='2019-03-01', date_format=DateFormat(format='DD.MM.YYYY'), currency_format=CurrencyFormat(iso_code='EUR', example_format='123.456,78', decimal_digits=2, decimal_separator=',', symbol_first=True, group_separator='.', currency_symbol='€', display_symbol=False)), Budget(id='00000000-0000-0000-0000-000000000000', name='Familienbudget old (Archived on 2019-10-31)', last_modified_on=datetime.datetime(2019, 11, 11, 19, 48, 10, tzinfo=tzutc()), first_month='2019-09-01', last_month='2019-12-01', date_format=DateFormat(format='DD.MM.YYYY'), currency_format=CurrencyFormat(iso_code='EUR', example_format='123.456,78', decimal_digits=2, decimal_separator=',', symbol_first=True, group_separator='.', currency_symbol='€', display_symbol=False)), Budget(id='00000000-0000-0000-0000-000000000000', name='Familienbudget (Archived on 2019-01-17)', last_modified_on=datetime.datetime(2019, 7, 2, 9, 2, 50, tzinfo=tzutc()), first_month='2018-04-01', last_month='2019-08-01', date_format=DateFormat(format='DD.MM.YYYY'), currency_format=CurrencyFormat(iso_code='EUR', example_format='123.456,78', decimal_digits=2, decimal_separator=',', symbol_first=True, group_separator='.', currency_symbol='€', display_symbol=False)), Budget(id='00000000-0000-0000-0000-000000000000', name='Unsere Finanzen', last_modified_on=datetime.datetime(2021, 2, 17, 17, 37, 8, tzinfo=tzutc()), first_month='2020-05-01', last_month='2021-02-01', date_format=DateFormat(format='DD.MM.YYYY'), currency_format=CurrencyFormat(iso_code='EUR', example_format='123.456,78', decimal_digits=2, decimal_separator=',', symbol_first=True, group_separator='.', currency_symbol='€', display_symbol=False)), Budget(id='00000000-0000-0000-0000-000000000000', name='Familie (old (Archived on 2020-09-18)', last_modified_on=datetime.datetime(2020, 9, 18, 13, 24, 14, tzinfo=tzutc()), first_month='2020-01-01', last_month='2020-10-01', date_format=DateFormat(format='DD.MM.YYYY'), currency_format=CurrencyFormat(iso_code='EUR', example_format='123.456,78', decimal_digits=2, decimal_separator=',', symbol_first=True, group_separator='.', currency_symbol='€', display_symbol=False)), Budget(id='00000000-0000-0000-0000-000000000000', name='Family Budget Before Fresh Start on 2016-05-01', last_modified_on=datetime.datetime(2018, 5, 8, 7, 10, 42, tzinfo=tzutc()), first_month='2015-12-01', last_month='2019-03-01', date_format=DateFormat(format='DD.MM.YYYY'), currency_format=CurrencyFormat(iso_code='EUR', example_format='123.456,78', decimal_digits=2, decimal_separator=',', symbol_first=True, group_separator='.', currency_symbol='€', display_symbol=False))]))

My configuration in YNAB looks like this:

ynab:
  api_key: "00000000000..."

@wxt9861
Copy link
Owner

wxt9861 commented Feb 22, 2021

Thank you. So it looks like the ynab-sdk is working correctly and the issue is in the component. Let me try to figure out how I can replicate this on my end so we can fix it.

@wxt9861
Copy link
Owner

wxt9861 commented Feb 23, 2021

I am still unable to replicate the issue however one of the issues with ynab_sdk is that it does not relay proper error codes, so it's hard to say exactly what is not working (ex: is it API key or something else?). I made some additions to the component to help us debug it (hopefully).

This version pulls budget summary and lets you know how many budgets it found (with their IDs) in the debug log.
Then it also says which budget id it is using to get the sensor data. If you have 1 budget the budget it finds and the one it is using should match. If you have multiple budgets, at least 1 found budget should match the one being used.

Please try the beta version and let me know what you find. Run it with debugging turned on for ynab component and let me know what results you get.

If you're going to paste debug log, please scrub it of any sensitive information.

logger:
  logs:
    custom_components.ynab: debug

https://github.com/wxt9861/ynab/releases/tag/v0.1.9b1

@lndnbrg
Copy link

lndnbrg commented Mar 5, 2021

Update 3:
Have finally figured out what caused the issue. In my case it was with the api, especially the get_budget call. The error was caused by some function that is handling the split transactions.

I have a certain type of split transaction (mix of category and account) that is causing this issue:
Transaction: Payee TEST / Outflow: 100€

Split 1: Category RENT / Outflow: 50€
Split 2: Account CREDITCARD / Outflow: 50€

When I create this kind of transaction in a test budget, that is working otherwise, it fails. As soon as I delete it, it is working fine.

Have created an issue with the ynab-sdk: andreroggeri/ynab-sdk-python#83

Thanks again for your help!


Hi thanks for your help!

I have done some debugging by myself, and this caused the error in init.py:

self.raw_budget = await self.hass.async_add_executor_job(
    self.ynab.budgets.get_budget, self.budget
)

I got this more detailled error message now:

2021-03-05 21:56:06 DEBUG (MainThread) [custom_components.ynab] Connection with YNAB established
2021-03-05 21:56:06 DEBUG (MainThread) [custom_components.ynab] YAML configured budget - 12345678-1a07-418c-8f76-e3ce5f23b4d6
2021-03-05 21:56:06 DEBUG (MainThread) [custom_components.ynab] Monitoring categories - []
2021-03-05 21:56:07 ERROR (MainThread) [homeassistant.components.sensor] ynab: Error on device update!
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 360, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 465, in async_device_update
await task
File "/config/custom_components/ynab/sensor.py", line 31, in async_update
await self.hass.data[DOMAIN_DATA]["client"].update_data()
File "/config/custom_components/ynab/__init__.py", line 110, in update_data
self.raw_budget = await self.hass.async_add_executor_job(
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.8/site-packages/ynab_sdk/api/budgets.py", line 17, in get_budget
return BudgetDetailResponse.from_dict(response)
File "/usr/local/lib/python3.8/site-packages/ynab_sdk/api/models/responses/budget_detail.py", line 505, in from_dict
data = Data.from_dict(obj.get("data"))
File "/usr/local/lib/python3.8/site-packages/ynab_sdk/api/models/responses/budget_detail.py", line 493, in from_dict
budget = Budget.from_dict(obj.get("budget"))
File "/usr/local/lib/python3.8/site-packages/ynab_sdk/api/models/responses/budget_detail.py", line 455, in from_dict
subtransactions = parsers.from_list(
File "/usr/local/lib/python3.8/site-packages/ynab_sdk/utils/parsers.py", line 47, in from_list
return [f(y) for y in x]
File "/usr/local/lib/python3.8/site-packages/ynab_sdk/utils/parsers.py", line 47, in <listcomp>
return [f(y) for y in x]
File "/usr/local/lib/python3.8/site-packages/ynab_sdk/api/models/responses/budget_detail.py", line 276, in from_dict
category_id = parsers.from_str(obj.get("category_id"))
File "/usr/local/lib/python3.8/site-packages/ynab_sdk/utils/parsers.py", line 16, in from_str
raise ex
File "/usr/local/lib/python3.8/site-packages/ynab_sdk/utils/parsers.py", line 11, in from_str
assert isinstance(x, str)
AssertionError

Update 1:
Did also modify the apitest.py and run it again:

from ynab_sdk import YNAB

try:
    api_key = "6978....fe3f"
    apicheck = YNAB(api_key)
    # print(apicheck.budgets.get_budgets())
    data = apicheck.budgets.get_budget("12345678-1a07-418c-8f76-e3ce5f23b4d6")
    print(data.data.budget.id)
except Exception:
    raise

I received the same response:

$ python3 apitest.py 
Traceback (most recent call last):
  File "/Users/andreas/Downloads/apitest.py", line 21, in <module>
    data = apicheck.budgets.get_budget("12345678-1a07-418c-8f76-e3ce5f23b4d6")
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ynab_sdk/api/budgets.py", line 17, in get_budget
    return BudgetDetailResponse.from_dict(response)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ynab_sdk/api/models/responses/budget_detail.py", line 505, in from_dict
    data = Data.from_dict(obj.get("data"))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ynab_sdk/api/models/responses/budget_detail.py", line 493, in from_dict
    budget = Budget.from_dict(obj.get("budget"))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ynab_sdk/api/models/responses/budget_detail.py", line 455, in from_dict
    subtransactions = parsers.from_list(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ynab_sdk/utils/parsers.py", line 47, in from_list
    return [f(y) for y in x]
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ynab_sdk/utils/parsers.py", line 47, in <listcomp>
    return [f(y) for y in x]
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ynab_sdk/api/models/responses/budget_detail.py", line 276, in from_dict
    category_id = parsers.from_str(obj.get("category_id"))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ynab_sdk/utils/parsers.py", line 16, in from_str
    raise ex
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ynab_sdk/utils/parsers.py", line 11, in from_str
    assert isinstance(x, str)
AssertionError

Update 2:
I figured out, that there is something in my budget. When I create a new budget with default settings, the upper code is working. Will try to find out what is different. If you have an idea what I shoud look for and try, please let me know.

Thank you!

@wxt9861
Copy link
Owner

wxt9861 commented Apr 8, 2021

@lndnbrg I see that your issue request was closed with an update. I am going to update dependency here and release an updated version in the next few days.

@wxt9861
Copy link
Owner

wxt9861 commented Aug 25, 2021

Closing issue as it was addressed in a dependency.

@wxt9861 wxt9861 closed this as completed Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants