Reputation: 1271
I am trying to import a csv data from google storage to a google cloud sql table, the operation status is stuck at RUNNING unless I exit the script
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)
Upvotes: 1
Views: 145
Reputation: 1078
A good place to start troubleshooting this is from Diagnosing issues with Cloud SQL instances.
I would start by viewing the Cloud SQL instance operation logs
Upvotes: 1