python-3.x - 通过 Google Cloud Function (Python) 从 BigQuery 数据库连接和查询
问题描述
我有
- 一个谷歌云函数(main.py + requirements.txt)
- bigQuery 数据库
- 工作查询
有人可以帮助我提供链接/教程/代码,以使用我在 Python 中的 Google Cloud Function 连接到这个 bigquery 数据库,并简单地从数据库中查询一些数据并显示它。
我尝试了https://cloud.google.com/bigquery/docs/reference/libraries但它与从正常部署连接到大查询有关,而不是 Google Cloud 功能。
这就是我到目前为止所拥有的。它正在部署没有错误,但在测试时,它给出了 500 错误
main.py(示例公共查询
from google.cloud import bigquery
def query_stackoverflow(request):
client = bigquery.Client()
query_job = client.query(
"""
SELECT
CONCAT(
'https://stackoverflow.com/questions/',
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')
要求.txt
google-cloud-bigquery
错误日志:
<!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>
解决方案
推荐阅读
- vba - Selenium VBA 中的网页加载
- excel - 在 Outlook 正文中将多个范围作为图片发送
- google-apps-script - 自动将 Google Drive 文件夹中最新 CSV 文件中的数据粘贴到 Google Sheet
- android - 如何使用 Mapbox Kotlin 在真实设备上显示当前位置
- react-native - 在无限动画中更改持续时间
- mysql - MySQL 存储过程没有按预期运行?
- c# - 获取 .NET Core 中的 SQL Server 列表
- wso2 - 从第一步禁用某些身份验证器的身份验证第二步
- spring - OpenAPI swagger UI is not responding for large response
- java - 在java中运行时创建2个sql表