Python でgoogle-cloud-storage
と、google-cloud-bigquery
を
スクリプトを
登録対象の
前提
以下の
OS
cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core)
Python
python3.6 -V Python 3.6.7
Google Cloud Storage
インストール後、
インストール
python3 -m pip install --upgrade google-cloud-storage --- Successfully installed google-api-core-1.3.0 google-cloud-core-0.28.1 google-cloud-storage-1.11.0 google-resumable-media-0.3.1 googleapis-common-protos-1.5.3 protobuf-3.6.1 requests-2.19.1
認証情報の 設定不備での エラー
認証情報の
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credential and re-run the application. For more information, please see
File "/usr/local/lib/python3.6/site-packages/google/auth/_default.py", line 292, in default raise exceptions.DefaultCredentialsError(_HELP_MESSAGE) google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credential and re-run the application. For more information, please see https://developers.google.com/accounts/docs/application-default-credentials.
GOOGLE_APPLICATION_CREDENTIALS
のPython スクリプトからGOOGLE_APPLICATION_CREDENTIALS
を
import os os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = './client_credentials.json'
storage.Client.from_service_account_json
を# Explicitly use service account credentials by specifying the private key # file. storage_client = storage.Client.from_service_account_json( 'service_account.json')
export GOOGLE_APPLICATION_CREDENTIALS="/Users/xxxxxxxxxx/keys//client_credentials.json"
権限設定時のストレージの<wbr>レガシー バケット<wbr>書き込み
を 付与する
Python スクリプトからの
File "/usr/local/lib/python3.6/site-packages/google/cloud/_http.py", line 293, in api_request raise exceptions.from_http_response(response) google.api_core.exceptions.Forbidden: 403 GET https://www.googleapis.com/storage/v1/b/xxxxxxxxxxxxxxxxxxxxxx.appspot.com?projection=noAcl: xxxxxxxxxxxxxx@Xxxxxxxxxxxxx.iam.gserviceaccount.com does not have storage.buckets.get access to xxxxxxxxxxxxxxxxxxxxxxx.appspot.com.
これはストレージの<wbr>レガシー バケット<wbr>書き込み
の
ストレージの<wbr>オブジェクト作成者
権限は
ストレージの<wbr>オブジェクト作成者
が
その他の 問題
上記の
全アカウントの
サポートに
焦りました。
BigQuery
インストール後に、
インストール
python3 -m pip install --upgrade google-cloud-bigquery ---------- Installing collected packages: google-cloud-bigquery Successfully installed google-cloud-bigquery-1.5.0 ----------
データセットの 指定文字列不備
データセット名のInvalid dataset ID
と
google.api_core.exceptions.BadRequest: 400 POST https://www.googleapis.com/bigquery/v2/projects/xxxxxxxxxxxx/jobs: Invalid dataset ID "xxxxxxxxx-xxxxxxxxxx". Dataset IDs must be alphanumeric (plus underscores) and must be at most 1024 characters long.
データセットが 存在しない
指定文字列の
return super(_AsyncJob, self).result(timeout=timeout) File "/usr/local/lib/python3.6/site-packages/google/api_core/future/polling.py", line 120, in result raise self._exception google.api_core.exceptions.NotFound: 404 Not found: Dataset xxxxxxxxx:table was not found in location US
テーブルに カラムが ない
テーブルに
raise exceptions.from_http_response(response) google.api_core.exceptions.NotFound: 404 GET https://www.googleapis.com/bigquery/v2/projects/xxxxxxxxxxx/datasets/aaaa/tables/column_name: Not found: Table xxxxxxxxxxx:aaaa.column_name
クレジットカードの 登録を 行っていない。
データセットの
Billing has not been enabled for this project. Enable billing at https://console.cloud.google.com/billing
https://console.cloud.google.com/billing
からこの
Spark
プラン から、Blaze
プランへ若干課金怖いですが、
テーブル名に、 全角フィールド名称は 作成できない。
CSV の_
に
フィールド名 | タイプ | モード |
---|---|---|
_______________ | STRING | NULLABLE |
_________ | INTEGER | NULLABLE |
____________ | INTEGER | NULLABLE |
h1______ | INTEGER | NULLABLE |
h2______ | INTEGER | NULLABLE |
h3______ | INTEGER | NULLABLE |
h4______ | INTEGER | NULLABLE |
h5______ | INTEGER | NULLABLE |
h6______ | INTEGER | NULLABLE |
table______ | INTEGER | NULLABLE |
li______ | INTEGER | NULLABLE |
dt______ | INTEGER | NULLABLE |
img______ | INTEGER | NULLABLE |
a______ | INTEGER | NULLABLE |
フィールド名が 違う CSV を 更新アップロードすると エラーに なる。
更新時の
テーブルを
File "/usr/local/lib/python3.6/site-packages/google/api_core/future/polling.py", line 120, in result raise self._exception google.api_core.exceptions.BadRequest: 400 Invalid schema update. Cannot add fields (field: fileName)
参考
以下、
BigQuery 関連
- BigQueryの
コストに 対する 恐怖心を 払拭する - BigQueryで
150万円溶かした 人の 顔 - 費用管理 | BigQuery | Google Cloud
- 料金 | BigQuery | Google Cloud
- Google BigQuery の
一般公開データセット | BigQuery | Google Cloud
Google Cloud Platform の 利用規約
経験の
以上です。
コメント