-1

I'm working on a Google Cloud Function to create a Service Account key, following these instructions: https://cloud.google.com/iam/docs/creating-managing-service-account-keys. Every time I deploy the function, I get this error, but I don't understand it. Can you please let me know what I am doing wrong? I am specifying the Service Account to use by setting a variable with the account's email address. The service account has been given the "Service Account Key Admin" role.

Function failed on loading user code. Error message: Code in file main.py can't be loaded. Detailed stack trace: Traceback (most recent call last): File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py", line 359, in check_or_load_user_function _function_handler.load_user_function() File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py", line 236, in load_user_function spec.loader.exec_module(main_module) File "", line 724, in exec_module File "", line 860, in get_code File "", line 791, in source_to_code File "", line 219, in _call_with_frames_removed File "/user_code/main.py", line 29 service_account_email = 'service-key-function-1@reference-rain-293933.iam.gserviceaccount.com' ^ TabError: inconsistent use of tabs and spaces in indentation

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441

2 Answers2

2

The service account has no relation with this error. Your Python code contains a mix of tabs and spaces for the indentation. Refactor your file with only space, or tab, but keep the same type for the indentation.

Dustin Ingram
  • 20,502
  • 7
  • 59
  • 82
guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
0

As Guillaume says, this is a code formatting error due to inconsistent use of tabs/spaces. I would recommend using an IDE such as VSCode with a Python plugin that can identify these errors before you deploy them to Google Cloud Platform.

tgall
  • 132
  • 4