0

I am using watson assistant with flask framework. Once the session expires i get the following error

ApiException(response.status_code, error_message, http_response=response) ibm_cloud_sdk_core.api_exception.ApiException: Error: NotFound: session id ba62bf14-87e-4c7b071b591e for agent instance 0e5c653c-9-b4e0-5a597c3e541e, Code: 404 , X-global-transaction-id: ffea409d54977b49 127.0.0.1 - - [03/Jul/2019 11:27:47] "GET / HTTP/1.1" 200

Refreshing the page does not create a new session

How to create a new session on this exception, so that I need not restart the local server ?

Quantum Dreamer
  • 432
  • 1
  • 6
  • 17

2 Answers2

1

You mention a 5 minute session timeout.

Watson Plus trial has this set for just testing, and is not intended to be production level. It cannot be changed.

Standard version and lite can use session but both were originally stateless. You should use the V1 API for these. You will have to manage the state, but you will no longer have a time out.

If you are using the paid version of Watson Plus, or premium you can change the time out within the assistant settings.

Simon O'Doherty
  • 9,259
  • 3
  • 26
  • 54
  • so to bypass that, record the idle time between 2 messages and if idle time greater than 5 mins, the create a new session , however the context wont be retreived – Quantum Dreamer Jul 11 '19 at 18:10
  • To bypass what? If you are using standard or lite, use V1 api and this isn’t an issue. If you are using Watson plus trial, it’s only going to work for 30 days anyway. If you have paid Watson plus. Timeout should be 60 minutes as default. – Simon O'Doherty Jul 11 '19 at 22:48
  • My point is NOT "how to extend the session beyond 5 mins" , "how to create a new session every 5 mins or when you refresh the screen." – Quantum Dreamer Jul 12 '19 at 07:28
  • 1
    You should have an application layer handling sessions, not the front end. You shouldn't be recreating new sessions every 5 minutes if you are on Watson Plus, as the payment would be based on number of new sessions a month. You would easily run up a huge bill on a large scale project. There is sample code in the Watson Github showing how to do V1. – Simon O'Doherty Jul 12 '19 at 10:55
  • I am running this on localhost. Opening a new window does not create a new session. Is this something to do with Flask test server or because its on local server? How do I scale it to multiple users? – Quantum Dreamer Jul 16 '19 at 20:35
  • Have you switched to V1 API? Or are you using WA Plus? – Simon O'Doherty Jul 17 '19 at 05:41
  • I am still in V2 but switched to Premium verison and timeout is now 24 hours.Now how do I handle the invalid session error. – Quantum Dreamer Aug 04 '19 at 02:51
0

You need to provide code, as any response will be blind and based on guesswork on what errors you have made, and there are many. But based on the fact that you failed to provide code, and still raised the question expecting someone to tell you what you did wrong then let's go with a rookie error.

I think you are creating the session as a global in your flask app, and maybe saving it it the app object. You probably have a route for the dialog, which makes use of the session. The code in this route, needs to catch the error, or test if the session is still valid, and recreate it. If you are catching the error, and trying to recreate the session, then you may have fallen foul of Python's global variable restrictions. Essentially if in a function you have a variable as the right side of an assignment, then its scope will be limited to the function.

Refreshing the web page, will not force the flask app to re-create the session. As you probably have that logic outside of any routes.

chughts
  • 4,210
  • 2
  • 14
  • 27
  • My bad!!. This is not a syntax or any Runtime error. This is a session timeout error very specific to IBM watson assistant, which has session timeout limit of 5 mins. I created a flask app and as soon as I type a message a new session is created, but session expires after 5 mins – Quantum Dreamer Jul 10 '19 at 19:12
  • 1
    I was referring to the Assistant session. As Simon O'Doherty mentions your app needs to manage the session, and check for expiration. – chughts Jul 11 '19 at 09:12