kat*_*wat 10 flask python-3.x google-bigquery google-cloud-functions
我有
有人可以帮助我提供链接/教程/代码,使用我的 Python 中的 Google Cloud 函数连接到这个 bigquery 数据库,并简单地从数据库中查询一些数据并显示它。
我尝试了https://cloud.google.com/bigquery/docs/reference/libraries,但它与从正常部署连接到大查询有关,而不是与Google Cloud Function连接。
这是我到目前为止所拥有的。部署时没有错误,但经过测试,出现 500 错误
main.py(公共查询示例
from google.cloud import bigquery
def query_stackoverflow(request):
client = bigquery.Client()
query_job = client.query(
"""
SELECT
CONCAT(
'/sf/',
CAST(id as STRING)) as url,
view_count
FROM `bigquery-public-data.stackoverflow.posts_questions`
WHERE tags like '%google-bigquery%'
ORDER BY view_count DESC
LIMIT 10"""
)
results = query_job.result() # Waits for job to complete.
return Response("{'message':'successfully connected'}", status=200, mimetype='application/json')
Run Code Online (Sandbox Code Playgroud)
要求.txt
google-cloud-bigquery
Run Code Online (Sandbox Code Playgroud)
错误日志:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>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.</p>
Run Code Online (Sandbox Code Playgroud)
gcloud iam service-accounts create connect-to-bigquery
gcloud projects add-iam-policy-binding your-project --member="serviceAccount:connect-to-bigquery@your-project.iam.gserviceaccount.com" --role="roles/owner"
Run Code Online (Sandbox Code Playgroud)
成功!
| 归档时间: |
|
| 查看次数: |
11845 次 |
| 最近记录: |