Reputation: 691
I want to extract a table from Bigquery, using python 2.7 and pycharm. I followed the steps proposed by the official google cloud website (https://cloud.google.com/bigquery/docs/exporting-data), but it keeps giving me the "AttributeError: 'module' object has no attribute 'ExtractJobConfig'" error.
The code:
from gcloud import bigquery
def bigquery_get_rows ():
#ININCIALIZACAO DO CLIENTE DE FORMA EXPLICITA
json_key = "path/to/my/json_key_File.json"
#storage_client = storage.Client.from_service_account_json(json_key)
bq_client = bigquery.Client.from_service_account_json(json_key,project='my_project_name')
print("\nPeguei o Cliente\n")
# Make an authenticated API request
#buckets = list(storage_client.list_buckets())
#print(buckets)
print("\nPRINTEI OS BUCKETS PARA TESTAR SE PEGOU O CLIENTE MERMO\n")
#print(storage_client)
print(bq_client)
print("\n NAO EH QUE EU PEGUEI O TAL DO CLIENTE MERMO")
#Setando ambiente
project = 'my_project'
print(project)
bucket_name = 'my_bucket'
print(bucket_name)
destination_uri = 'gs://{}/{}'.format(bucket_name, 'TESTE_Lista_Padrao_Mailchimp_Automatizada.json')
print(destination_uri)
dataset_ref = bq_client.dataset('my_dataser_ref')
print(dataset_ref)
table_ref = dataset_ref.table(name='my_table_ref')
print(table_ref)
#Configuracao do job
job_config = bigquery.job.ExtractJobConfig()
job_config.destination_format = (bigquery.DestinationFormat.NEWLINE_DELIMITED_JSON)
#Extraindo tabela
extract_job = bq_client.extract_table(table_ref, destination_uri, job_config=job_config,location='US') # API request
extract_job.result() # Waits for job to complete.
print('Exported {}:{}.{} to {}'.format(project, dataset_id, table_id, destination_uri))
bigquery_get_rows()
Upvotes: 1
Views: 2879
Reputation: 691
Turns out I was using the wrong library.
I just changed from
from gcloud import bigquery
to
from google.cloud import bigquery
and it is working now
Upvotes: 1