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

bunq.sdk.exception.BunqException: ApiContext has not been loaded. Please load ApiContext in BunqContext #92

Closed
CharlPels opened this issue Apr 13, 2018 · 6 comments

Comments

@CharlPels
Copy link

Steps to reproduce:

  1. first create a conf file using something like

def register():
ctx = context.ApiContext(
context.ApiEnvironmentType.PRODUCTION,
"",
''
)

ctx.save()
ctx_restored = context.ApiContext.restore()
print('Is original context equal the one saved and restored?:',
converter.class_to_json(ctx) == converter.class_to_json(ctx_restored))

register()

using a simple like this one
https://github.com/bunq/sdk_python/blob/develop/examples/customer_statement_export_example.py#L24
line 24: api_context = context.ApiContext.restore() works with no issue and I see context info
line 25: user_id = endpoint.User.list(api_context).value[INDEX_FIRST]
.UserCompany.id

here you get the error
bunq.sdk.exception.BunqException: ApiContext has not been loaded. Please load ApiContext in BunqContext

What should happen:

  1. giving a user list

What happens:

  1. get and error (bunq.sdk.exception.BunqException: ApiContext has not been loaded. Please load ApiContext in BunqContext)

Traceback

SDK version and environment

  • Tested on bunq-sdk-0.13.0
    production

Response id

  • Response id:

Extra info:

Had no issue with my code using older sdk, with new sdk it stops working

@OGKevin
Copy link
Contributor

OGKevin commented Apr 13, 2018

Closing this issue as its not an bug.

Please see: https://github.com/bunq/tinker_python/blob/3898543198df8c5a496fdb35dd70c994c556b102/tinker/libs/bunq_lib.py#L69-L73 for example on how to load the api context.

@OGKevin OGKevin closed this as completed Apr 13, 2018
@CharlPels
Copy link
Author

Hello,

It looks like an issue, your sample has the same issue
the loading of the context is no issue, using it gives problems
simple commands like this endpoint.User.list(api_context).value are not working anymore.

tested your sample and the examples from github

for storing i user this (from this github)
https://github.com/bunq/sdk_python/blob/develop/examples/api_context_save_example.py

then use something like this
https://github.com/bunq/sdk_python/blob/develop/examples/user_list_example.py

and you will get the same error
this are the basic samples, just copy/paste using production keys and calling the function

@OGKevin
Copy link
Contributor

OGKevin commented Apr 13, 2018

These examples are outdated. see #84.

You must load the Api context before using it as shown here: https://github.com/bunq/tinker_python/blob/3898543198df8c5a496fdb35dd70c994c556b102/tinker/libs/bunq_lib.py#L69-L73

endpoint.User.list(api_context) is not a valid function call. see the code:

@classmethod
def list(cls, params=None, custom_headers=None):
"""
Get a collection of all available users.
:type params: dict[str, str]|None
:type custom_headers: dict[str, str]|None
:rtype: BunqResponseUserList
"""

@CharlPels
Copy link
Author

Hello OGKevin,

Maybe a stupid question but why are the examples not updated?

I see the code
api_context = ApiContext.restore(self.determine_bunq_conf_filename())
api_context.ensure_session_active()
api_context.save(self.determine_bunq_conf_filename())
BunqContext.load_api_context(api_context)
and have no clue how to use this in my code

I am not a fulltime developer :-)

@OGKevin
Copy link
Contributor

OGKevin commented Apr 14, 2018

Had no issue with my code using older sdk, with new sdk it stops working

you have updated from 0.12.5 to 0.13.0 this means a breaking update 😉 as the major version number has changed.

after you have ran BunqContext.load_api_context(api_context) you can preform calls without having to pass api context. e.g. https://github.com/bunq/tinker_python/blob/2182b8be276fda921657ad22cfe0b8b48a585ccf/tinker/libs/bunq_lib.py#L105-L115

Maybe a stupid question but why are the examples not updated?

because they were examples and not essential to the release and therefore forgotten. Hence examples will be replaced with tinker as tinker contains enough "example code".

@CharlPels
Copy link
Author

CharlPels commented Apr 14, 2018

Kevin,

Can you provide an actual working running sample I can use as a starting point, not pointing to parts of this class but a actual sample I could run to for example read transactions, sending money or something.
For the developers like me that don’t program all day and just want to use the api just for some basic automation

Regards,
Charl

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

2 participants