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

VCAP_Services Error #33

Open movinglightspeed opened 3 years ago

movinglightspeed commented 3 years ago

https://github.com/IBM-Cloud/get-started-python/blob/master/hello.py

Waiting for app to start... Start unsuccessful

TIP: use 'cf.exe logs myapp --recent' for more information FAILED

ibmcloud cf logs myapp --recent 2021-01-12T06:02:32.28-0600 [CELL/0] OUT Starting health monitoring of container 2021-01-12T06:02:39.91-0600 [APP/PROC/WEB/0] ERR Traceback (most recent call last): 2021-01-12T06:02:39.91-0600 [APP/PROC/WEB/0] OUT Found VCAP_SERVICES 2021-01-12T06:02:39.94-0600 [APP/PROC/WEB/0] ERR File "hello.py", line 19, in 2021-01-12T06:02:39.94-0600 [APP/PROC/WEB/0] ERR password = creds['password'] 2021-01-12T06:02:39.94-0600 [APP/PROC/WEB/0] ERR KeyError: 'password' 2021-01-12T06:02:40.43-0600 [APP/PROC/WEB/0] OUT Exit status 1 2021-01-12T06:02:40.49-0600 [CELL/SSHD/0] OUT Exit status 0

From GUI TypeInstanceLogsTime APP/PROC/WEB0Traceback (most recent call last):

Jan 12, 2021, 05:42:07 AM

APP/PROC/WEB0 File "hello.py", line 19, in

Jan 12, 2021, 05:42:07 AM APP/PROC/WEB0 password = creds['password']

Jan 12, 2021, 05:42:07 AM APP/PROC/WEB0KeyError: 'password'

Jan 12, 2021, 05:42:07 AM

movinglightspeed commented 3 years ago

update: I realized the reason was because the cloudant database was IAM only not IAM + Legacy which supports the username + password.

It would be good if the code was updated to support also the IAM only cloudant database offering, offering support for the IAM apikey + access token support as iam apikey alone can't authenticate against a cloudant database as stated from docs:

https://github.com/IBM/cloudant-python-sdk#iam-authentication

"You can't use an IAM API key directly to authenticate against IBM Cloudant." https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-connecting

It would be great to see a implementation of IAM API key + Access token in a python app starter code

emlaver commented 3 years ago

Just to clarify, while you can't use an IAM API key directly when using cURL (you must first get an IBM Cloud IAM token by using an API key) you can use the IAM API key to authenticate in our python-cloudant library. There's an example of authenticating with IAM in our python-cloudant documentation.

movinglightspeed commented 3 years ago

@emlaver Thanks for clarifying that! That was it, that statement in the documentation caused alot of confusion. To further add to my wrong conclusions, starter kits all used legacy creds, led me to believe iam didn't work for apps and thought what a security risk!

This cleared it up and I used the code in the example you shared and successfully tested an app connection to the db. I was able to create, update using iam connection.