0

Trying to integrate Google's BigQuery with Azure Function App but getting error

IMPORTS

import azure.functions as func
from google.cloud import bigquery as bq
import os

CODE

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/my/service-account-file.json"
client = bq.Client() # Initiate connection

# Read query
res = client.query("select * from project.dataset.table limit 1")

During execution

Worker failed to function id 4f6bc6a6-21e7-4be2-8d74-7ba865534799.
[2022-06-03T11:36:21.743Z] Result: Failure
Exception: AttributeError: 'NoneType' object has no attribute 'message_types_by_name'
Stack:   File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools-3\tools\workers\python\3.8\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 266, in _handle__function_load_request
    func = loader.load_function(
  File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools-3\tools\workers\python\3.8\WINDOWS\X64\azure_functions_worker\utils\wrappers.py", line 32, in call
    return func(*args, **kwargs)
  File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools-3\tools\workers\python\3.8\WINDOWS\X64\azure_functions_worker\loader.py", line 76, in load_function
    mod = importlib.import_module(fullmodname)
  File "C:\Users\Admin\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\Admin\Projects\rocket_application\source\source-backend-code\payments_v3\__init__.py", line 16, in <module>
    from google.cloud import bigquery
  File "C:\Users\Admin\Projects\rocket_application\source\.env\lib\site-packages\google\cloud\bigquery\__init__.py", line 35, in <module>
    from google.cloud.bigquery.client import Client
  File "C:\Users\Admin\Projects\rocket_application\source\.env\lib\site-packages\google\cloud\bigquery\client.py", line 52, in <module>
    import google.api_core.exceptions as core_exceptions
  File "C:\Users\Admin\Projects\rocket_application\source\.env\lib\site-packages\google\api_core\exceptions.py", line 29, in <module>
    from google.rpc import error_details_pb2
  File "C:\Users\Admin\Projects\rocket_application\source\.env\lib\site-packages\google\rpc\error_details_pb2.py", line 39, in <module>
    _RETRYINFO = DESCRIPTOR.message_types_by_name["RetryInfo"]

When the same is executed with simple python code, it returns the results from big query table.

Ajit
  • 1
  • 1
  • Does this answer your question? [Why do I get AttributeError: 'NoneType' object has no attribute 'something'?](https://stackoverflow.com/questions/8949252/why-do-i-get-attributeerror-nonetype-object-has-no-attribute-something) – Ecstasy Jun 06 '22 at 05:02
  • [Python gprc AttributeError: 'NoneType' object has no attribute 'message_types_by_name'](https://stackoverflow.com/questions/71906577/python-gprc-attributeerror-nonetype-object-has-no-attribute-message-types-by), [AttributeError: 'NoneType' object has no attribute 'message_types_by_name'](https://stackoverflow.com/questions/72280081/attributeerror-nonetype-object-has-no-attribute-message-types-by-name) – Ecstasy Jun 06 '22 at 05:08
  • No @DeepDave-MT, I’ve tried these articles. The problem is when I simply run the code without any wrapper like azure function, it runs and produces the output. But when the some code is added to the function code, azure local server fails to start and then automatically shuts the server down. – Ajit Jun 07 '22 at 06:04
  • [Azure auto shuts down only after 1 minute of running.](https://learn.microsoft.com/en-us/answers/questions/575522/azure-auto-shuts-down-only-after-1-minute-of-runni.html), [Host is shutting down - Azure Functions](https://learn.microsoft.com/en-us/answers/questions/806775/host-is-shutting-down-azure-functions.html) and [Local Azure Function Shutting Down Automatically](https://stackoverflow.com/questions/57791706/local-azure-function-shutting-down-automatically) – Ecstasy Jun 07 '22 at 06:32

0 Answers0