Reputation: 1033
I am trying to connect to a BigQuery table from a google cloud function but my function returns the following error:
Error: function terminated. Recommended action: inspect logs for termination reason. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging Details: 500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
When I inspect the logs, I see the following error:
Traceback (most recent call last): File "/layers/google.python.pip/pip/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app response = self.full_dispatch_request() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request rv = self.handle_user_exception(e) File "/layers/google.python.pip/pip/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request rv = self.dispatch_request() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) File "/layers/google.python.pip/pip/lib/python3.9/site-packages/functions_framework/init.py", line 99, in view_func return function(request._get_current_object()) File "/workspace/main.py", line 72, in entry client = bigquery.Client() AttributeError: 'function' object has no attribute 'Client'
I don't understand why the attribute 'Client' doesn't exist. I believe I have imported bigquery correctly. Here is my entry point function with the simple test script:
import os
import json
from google.cloud import bigquery
def entry(request):
client = bigquery.Client()
query_job = client.query("""SELECT MAX(day) FROM `name of project and bigquery table`""")
for i in query_job:
print(i[0])
return "ok"
Here is my requirements.txt file
google-cloud-bigquery
sqlalchemy==1.4.37
pandas==1.4.2
PyMySQL==1.0.2
Any pointers would be greatly appreciated.
Upvotes: 0
Views: 1025
Reputation: 1033
UPDATE
I had another function within my cloud function with was called bigquery. I think this caused a conflict with my import of bigquery in the third line of my code. I believe this is the root cause of my issue.
Upvotes: 1