bunq / sdk_python

Python SDK for bunq API
MIT License
106 stars 25 forks source link

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

Closed CharlPels closed 6 years ago

CharlPels commented 6 years ago

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[_INDEXFIRST]\ .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

Response id

Extra info:

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

OGKevin commented 6 years ago

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.

CharlPels commented 6 years ago

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 commented 6 years ago

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: https://github.com/bunq/sdk_python/blob/25c6e353dfcefedfd4e1cd01e6cea529c710e7ef/bunq/sdk/model/generated/endpoint.py#L14895-L14904

CharlPels commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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