I have a function:
def UPLOAD(FILE_NAME):
try:
client = bigquery.Client()
dataset_ref = client.dataset(DATASET)
table_ref = dataset_ref.table(TABLE)
job_config = bigquery.LoadJobConfig()
job_config.source_format = bigquery.SourceFormat.NEWLINE_DELIMITED_JSON
job_config.autodetect = False
with open(FILE_NAME, 'rb') as source_file:
job = client.load_table_from_file(
source_file,
table_ref,
location='EU', # Must match the destination dataset location.
job_config=job_config) # API request
job.result() # Waits for table load to complete.
except:
error(job,'BLABLA')
The issue in this function that when I try to pass the job
parameter from except to error function it not picking it up.
What is the actual error, I'm not sure...
ERROR: Error: local variable 'job' referenced before assignment
UPDATE:
def error(job,extra):
if extra == 'BLABLA':
ERROR = job.error
elif extra == 'LALA':
ERROR = job.error
else:
print('else')