【问题标题】:google cloud operation stuck at RUNNING unless I exit the script除非我退出脚本,否则谷歌云操作卡在 RUNNING
【发布时间】:2021-03-20 15:27:23
【问题描述】:

我正在尝试将 csv 数据从谷歌存储导入到谷歌云 sql 表中,除非我退出脚本,否则操作状态卡在 RUNNING

credentials_dict = {...}  # service account json
credentials = service_account.Credentials.from_service_account_info(
    credentials_dict, scopes=['https://www.googleapis.com/auth/cloud-platform']
)
authed_session = AuthorizedSession(credentials)
payload={
"importContext":
{
    "fileType": "CSV",
    "uri": "gs://<path-to-csv>",
    "database": "<db-name>",
    "csvImportOptions":
    {
        "table": "<table-name>"
    }
}
}
response = authed_session.request('POST', 
    'https://www.googleapis.com/sql/v1beta4/projects/<project-id>/instances/<cloude-sql-instance-id>/import',json=payload)
data = json.loads(response.text)
name = data["name"]
while response.status_code == 200 and  data["status"] != "DONE":
    sleep(5)
    response = authed_session.request(
    'GET', 'https://www.googleapis.com/sql/v1beta4/projects/<project-id>/operations/' + name)
    data = json.loads(response.text)

【问题讨论】:

标签: python google-cloud-platform gcloud google-cloud-sql


【解决方案1】:

Diagnosing issues with Cloud SQL instances 开始解决此问题的好地方。

我会先查看Cloud SQL instance operation logs

【讨论】:

  • 问题是在 with psycopg2 /conn.cursor() 块中调用 import_csv_to_table 代码来创建数据表,conn.commit() 解决了这个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-30
  • 1970-01-01
  • 1970-01-01
  • 2022-12-17
  • 2021-11-20
相关资源
最近更新 更多