Google BigQuery Python Client Issue in Azure Function

BenjaVaisberg 1 Reputation point
2022-08-02T21:00:01.85+00:00

I am getting an error when trying to import the Google BigQuery Python Client in an Azure Function. This works fine if I test somewhere else like a local script or Jupyter Notebook.

from google.cloud import bigquery  

Leads to this error:

[2022-08-02T21:01:52.607] Worker failed to function id ec06ba50-3e6a-4352-84a9-7376e440da11.  
[2022-08-02T21:01:52.608] Result: Failure  
Exception: AttributeError: 'NoneType' object has no attribute 'message_types_by_name'  
Stack:   File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.8/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 262, in _handle__function_load_request  
    func = loader.load_function(  
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.8/WINDOWS/X64\azure_functions_worker\utils\wrappers.py", line 32, in call  
    return func(*args, **kwargs)  
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.8/WINDOWS/X64\azure_functions_worker\loader.py", line 76, in load_function  
    mod = importlib.import_module(fullmodname)  
  File "C:\Python38\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\bvaisberg\Desktop\TestFuncApp\TestHttpTrigger\__init__.py", line 5, in <module>  
    from google.cloud import bigquery  
  File "c:\Users\bvaisberg\Desktop\TestFuncApp\.venv\lib\site-packages\google\cloud\bigquery\__init__.py", line 35, in <module>  
    from google.cloud.bigquery.client import Client  
  File "c:\Users\bvaisberg\Desktop\TestFuncApp\.venv\lib\site-packages\google\cloud\bigquery\client.py", line 52, in <module>  
    import google.api_core.exceptions as core_exceptions  
  File "c:\Users\bvaisberg\Desktop\TestFuncApp\.venv\lib\site-packages\google\api_core\exceptions.py", line 29, in <module>  
    from google.rpc import error_details_pb2  
  File "c:\Users\bvaisberg\Desktop\TestFuncApp\.venv\lib\site-packages\google\rpc\error_details_pb2.py", line 39, in <module>  
    _RETRYINFO = DESCRIPTOR.message_types_by_name["RetryInfo"]  
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,936 Reputation points Moderator
    2022-08-05T04:27:00.697+00:00

    @BenjaVaisberg Thanks for reaching out. As per the error it looks like the module might not have correctly loaded or installed on your function runtime.
    You should be leveraging the requirement.txt file rather than import_module
    mod = importlib.import_module(fullmodname)

    If you have any requirement where you need to use any other packages that are not predefined in the functions then you need to add the names or names along with versions of the required packages to the requirements.txt file. Please refer to this document for more details. As you are leveraging the Google BigQuery API so I believe this would be the python package that you should be leveraging.

    To troubleshoot these types of errors you can always refer to this document.

    Your requirement.txt file will be as below but in case if you are using any other packages then please make sure that you have defined the same.

     azure-functions  
     google-cloud-bigquery   
    

    For your reference, I will suggest you to review this article which will can help you to monitor azure function. Once you have set it up you can see the above error in application insights. You can also see these exceptions in the storage account that you have configured on your function app.

    Please refer to Azure function python document to get more familiar with the development and update your python code according.

    Feel free to get back to me if you have any queries or concerns.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.