我在终端中运行 CURL 时出现错误。错误是这样的:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
这是我的卷曲代码:
ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
curl --header "Authorization: Bearer ${ACCESS_TOKEN}"
--header 'Content-Type: application/json'
--data '{"exportContext":
{"fileType": "CSV",
"uri": "gs://project-initial-db/test_gutil.csv",
"databases": ["my_db"] },
"csvExportOptions":
{"selectQuery":"SELECT * FROM `trans_channel` INTO OUTFILE "test_gutil.csv" CHARACTER SET "utf8mb4" FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """ ESCAPED BY "\" LINES TERMINATED BY "n";"}}'
-X POST
https://www.googleapis.com/sql/v1beta4/projects/project-11/instances/project-db/export
有人知道这个错误吗?
我在Google Cloud SQL上使用CURL寻找有关导出到CSV的信息,但我只得到了一些信息。
仅供参考,我已经设置了环境变量(GOOGLE_APPLICATION_CREDENTIALS)并且身份验证成功。
如果您能提供任何帮助,我将不胜感激。谢谢!
你只是在"cvsExportOptions"字段中缺少一些东西,它应该看起来像这样:
"csvExportOptions":
{"selectQuery":"[YOUR_QUERY]"}
您可能在此处提供了更多详细信息,您还可以使用页面右侧的试用 API 实用程序检查 curl 是否正确。
编辑
从我用于测试的"试用此 API"实用程序复制 api 调用,因为它对我有用。尝试用您的数据替换占位符
ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
curl --header "Authorization: Bearer ${ACCESS_TOKEN}"
--header 'Content-Type: application/json'
--data '{
"exportContext": {
"fileType": "CSV",
"uri": "gs://[YOUR_BUCKET]/[YOUR_PATH_TO_DUMP_FILE]",
"databases": [
"[YOUR_DATABASE]"
],
"csvExportOptions": {
"selectQuery": "[YOUR_QUERY]"
}
}
}'
-X POST
https://www.googleapis.com/sql/v1beta4/projects/[YOUR_PROJECT]/instances/[YOUR_INSTANCE]/export