質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
BigQuery

BigQueryは、Google Cloud Platformが提供しているビッグデータ解析サービス。数TB(テラバイト)またはPB(ペタバイト)の膨大なデータに対し、SQL風のクエリを実行し、高速で集計・分析を行うサービスです。

Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

0回答

3062閲覧

PythonからのBigQuery認証でbigquery.jobs.create permissionがAccess Deniedされてしまいます

nyayuta

総合スコア2

BigQuery

BigQueryは、Google Cloud Platformが提供しているビッグデータ解析サービス。数TB(テラバイト)またはPB(ペタバイト)の膨大なデータに対し、SQL風のクエリを実行し、高速で集計・分析を行うサービスです。

Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2019/08/12 12:30

いろいろ試しましたが、認証が通りません。なにとぞよろしくお願いいたします。

前提・実現したいこと

PythonからBigQueryを利用したいです。
認証を取るためにサービスアカウントをjsonファイルで取得しています。
そして、GoogleCloudPlatformの"IAMと管理"の画面から、
取得したサービスアカウントに、

  • BigQuery 管理者
  • BigQuery データオーナー
  • BigQuery ジョブユーザー
  • サービス アカウント ユーザー
  • オーナー

の5つの権限を付与しています(足りないのでは、と増やした結果です)。

発生している問題・エラーメッセージ

InvalidResponse Traceback (most recent call last) /usr/local/lib/python3.6/dist-packages/google/cloud/bigquery/client.py in load_table_from_file(self, file_obj, destination, rewind, size, num_retries, job_id, job_id_prefix, location, project, job_config) 1430 response = self._do_resumable_upload( -> 1431 file_obj, job_resource, num_retries 1432 ) /usr/local/lib/python3.6/dist-packages/google/cloud/bigquery/client.py in _do_resumable_upload(self, stream, metadata, num_retries) 1586 upload, transport = self._initiate_resumable_upload( -> 1587 stream, metadata, num_retries 1588 ) /usr/local/lib/python3.6/dist-packages/google/cloud/bigquery/client.py in _initiate_resumable_upload(self, stream, metadata, num_retries) 1629 upload.initiate( -> 1630 transport, stream, metadata, _GENERIC_CONTENT_TYPE, stream_final=False 1631 ) /usr/local/lib/python3.6/dist-packages/google/resumable_media/requests/upload.py in initiate(self, transport, stream, metadata, content_type, total_bytes, stream_final) 326 retry_strategy=self._retry_strategy) --> 327 self._process_initiate_response(result) 328 return result /usr/local/lib/python3.6/dist-packages/google/resumable_media/_upload.py in _process_initiate_response(self, response) 448 self._resumable_url = _helpers.header_required( --> 449 response, u'location', self._get_headers) 450 /usr/local/lib/python3.6/dist-packages/google/resumable_media/_helpers.py in header_required(response, name, get_headers, callback) 63 raise common.InvalidResponse( ---> 64 response, u'Response headers must contain header', name) 65 InvalidResponse: ('Response headers must contain header', 'location') During handling of the above exception, another exception occurred: Forbidden Traceback (most recent call last) <ipython-input-46-b985c2114c26> in <module>() 1 if __name__=='__main__': ----> 2 main() <ipython-input-45-5e967183c75f> in main() 27 28 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ---> 29 insert_into_bigquery_table(dataframe, fiscal_year) 30 print('complete!!') <ipython-input-44-85a5177f0da3> in insert_into_bigquery_table(dataframe, FY) 7 print(FY) 8 ----> 9 job = client.load_table_from_dataframe(dataframe, table_ref, location='asia-northeast1') 10 job.result() /usr/local/lib/python3.6/dist-packages/google/cloud/bigquery/client.py in load_table_from_dataframe(self, dataframe, destination, num_retries, job_id, job_id_prefix, location, project, job_config, parquet_compression) 1561 location=location, 1562 project=project, -> 1563 job_config=job_config, 1564 ) 1565 /usr/local/lib/python3.6/dist-packages/google/cloud/bigquery/client.py in load_table_from_file(self, file_obj, destination, rewind, size, num_retries, job_id, job_id_prefix, location, project, job_config) 1436 ) 1437 except resumable_media.InvalidResponse as exc: -> 1438 raise exceptions.from_http_response(exc.response) 1439 1440 return self.job_from_resource(response.json()) Forbidden: 403 POST https://www.googleapis.com/upload/bigquery/v2/projects/xxxxxxxxxxx/jobs?uploadType=resumable: Access Denied: Project xxxxxxxxxxxx: The user xxxxxxxxxxx@xxxxxxx.iam.gserviceaccount.com does not have bigquery.jobs.create permission in project xxxxxxxxxx.

該当のソースコード

Python

1from google.cloud import bigquery 2(中略) 3def insert_into_bigquery_table(dataframe, FY): 4 client = bigquery.Client.from_service_account_json('jsonへのpass/xxxxxxxxxxxxxxx.json') 5 6 dataset_ref = client.dataset('xxxxxxx') 7 table_ref = dataset_ref.table(FY) 8 print(FY) 9 10 job = client.load_table_from_dataframe(dataframe, table_ref, location='asia-northeast1') 11 job.result()

試したこと

  • 様々な権限(上記の5つ)の付与
  • 3時間程度、時間をおいて再度実行
  • サービスアカウントの作り直し

補足情報(FW/ツールのバージョンなど)

GoogleColaboratoryから使用しています。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問