IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Using Python to run BigQuery job with project id

    RobinDong发表于 2022-11-18 02:17:26
    love 0

    Here is the code for me to query a table of BigQuery:

    from google.cloud import bigquery
    from google.cloud.bigquery_storage import BigQueryReadClient
    
    client = bigquery.Client()
    storage_client = BigQueryReadClient()
    df = client.query("select * from my_table1").to_dataframe(bqstorage_client=storage_client)

    Then it reported the error:

    “Access Denied: Project PRJ_B: User does not have bigquery.jobs.create permission in project PRJ_B.”

    But actually, I want to launch a job in project PRJ_A. So I add a shell command “gcloud config set project PRJ_A” before running this python script. But the errors continued.

    After searching the API doc of Python BigQuery, I found out that the “bigquery.Client()” function could add an argument:

    client = bigquery.Client(project="PRJ_A")

    Now the script works well.



沪ICP备19023445号-2号
友情链接