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.
# hello.py
if 'VCAP_SERVICES' in os.environ:
vcap = json.loads(os.getenv('VCAP_SERVICES'))
print('Found VCAP_SERVICES')
if 'cloudantNoSQLDB' in vcap:
creds = vcap['cloudantNoSQLDB'][0]['credentials']
user = creds['username']
password = creds['password']
url = 'https://' + creds['host']
client = Cloudant(user, password, url=url, connect=True)
db = client.create_database(db_name, throw_on_exists=False)
Error
2021-04-05T17:44:13.52+0100 [CELL/0] OUT Starting health monitoring of container
2021-04-05T17:44:17.79+0100 [APP/PROC/WEB/0] OUT Found VCAP_SERVICES
2021-04-05T17:44:17.79+0100 [APP/PROC/WEB/0] ERR Traceback (most recent call last):
2021-04-05T17:44:17.79+0100 [APP/PROC/WEB/0] ERR File "hello.py", line 19, in <module>
2021-04-05T17:44:17.79+0100 [APP/PROC/WEB/0] ERR password = creds['password']
2021-04-05T17:44:17.79+0100 [APP/PROC/WEB/0] ERR KeyError: 'password'
2021-04-05T17:44:17.90+0100 [APP/PROC/WEB/0] OUT Exit status 1
2021-04-05T17:44:17.92+0100 [CELL/SSHD/0] OUT Exit status 0
Maybe client = Cloudant.iam(ACCOUNT_NAME, API_KEY, connect=True) should be used instead to establish a connection
When linking a cloudant service to the app there is no
password
parameter in the credentials. It seems there is only a api key is present.The app then crashed due to no password:
Error
Maybe
client = Cloudant.iam(ACCOUNT_NAME, API_KEY, connect=True)
should be used instead to establish a connection