2
votes

Have written GCP Cloud Function in Python 3.7. While executing, sys.exit() I'm getting 'A server error occurred ...'. I need to exit out of the function and have written following code.

import sys 
if str(strEnabled) == 'True':
        printOperation = "Operation: Enabling of user" 
else:
        sys.exit() #Exit From the Program

Please suggest, what I'm missing here.

1
Use return instead of sys.exit - bigbounty
Your cloud function starts life with an HTTP request. It should return an HTTP status when the HTTP request is finished. Calling exit() is considered an exception, which means your code crashed. By calling return instead, your code is returning a success status (HTTP 200). - John Hanley

1 Answers

2
votes

Use return instead of sys.exit

Copied from bigbounty's comment