IBM-Cloud / get-started-python

A Python application and tutorial that use Flask framework to provide a REST API to receive requests from the UI. The API then persists the data to a Cloudant database.
https://console.ng.bluemix.net/docs/runtimes/python/getting-started.html
Apache License 2.0
121 stars 446 forks source link

401 Client Error from the backend cloudant database #30

Closed tnakajo closed 4 years ago

tnakajo commented 4 years ago

ISSUE If you leave the application for a few days+ without touching, the app will get the 401 Client Error from the backend cloudant database.

STEPS On the app page, submit a data in the What is your name field. It should work to insert the data in the backend cloudant database. Leave the app for a few days+ without touching. On the app page, submit a data in the What is your name field. The page is not responding. Check the app log or the browser network trace and you'll see the following error from the backend cloudant database.

requests.exceptions.HTTPError: 401 Client Error: Unauthorized unauthorized one of _writer, _creator is required for this request for url: https://***-bluemix.cloudantnosqldb.appdomain.cloud/mydb
tnakajo commented 4 years ago

As per my testing, I confirmed that the following change in the hello.py has resolved the issue.

[BEFORE] client = Cloudant(user, password, url=url, connect=True) [AFTER] client = Cloudant(user, password, url=url, connect=True, auto_renew=True)

It seems it was caused by the cookie authentication with the python/cloudant library.

References: https://cloud.ibm.com/docs/Cloudant/api?topic=Cloudant-authentication#cookie-authentication https://python-cloudant.readthedocs.io/en/stable/getting_started.html

I hope it will help.