Environments
Anaconda 3
Python 3.6.5
Jupyter notebook 5.5.0
pandas==0.23.0
pandas-gbq==0.6.0
Code I tried
import pandas as pd
query = "Select * FROM sample_tbl.my_data"
data_frame = pd.read_gbq(query, '[project name]', private_key="[path to key]", dialect='standard')
Error Message
The message I forcused
GenericGBQException: Reason: 404 GET https://www.googleapis.com/bigquery/v2/projects/[project name]/queries/1e2d0ee4-2f19-440e-82e3-03b1bae0b52e?maxResults=0&timeoutMs=900: Not found: Job [project name]:1e2d0ee4-2f19-440e-82e3-03b1bae0b52e
Whole message
NotFound Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/pandas_gbq/gbq.py in run_query(self, query, **kwargs)
276 try:
--> 277 query_reply.result(timeout=timeout_sec)
278 except TimeoutError:
~/anaconda3/lib/python3.6/site-packages/google/cloud/bigquery/job.py in result(self, timeout, retry)
2642 """
-> 2643 super(QueryJob, self).result(timeout=timeout)
2644 # Return an iterator instead of returning the job.
~/anaconda3/lib/python3.6/site-packages/google/cloud/bigquery/job.py in result(self, timeout)
687 # TODO: modify PollingFuture so it can pass a retry argument to done().
--> 688 return super(_AsyncJob, self).result(timeout=timeout)
689
~/anaconda3/lib/python3.6/site-packages/google/api_core/future/polling.py in result(self, timeout)
114 """
--> 115 self._blocking_poll(timeout=timeout)
116
~/anaconda3/lib/python3.6/site-packages/google/cloud/bigquery/job.py in _blocking_poll(self, timeout)
2616 self._done_timeout = timeout
-> 2617 super(QueryJob, self)._blocking_poll(timeout=timeout)
2618
~/anaconda3/lib/python3.6/site-packages/google/api_core/future/polling.py in _blocking_poll(self, timeout)
93 try:
---> 94 retry_(self._done_or_raise)()
95 except exceptions.RetryError:
~/anaconda3/lib/python3.6/site-packages/google/api_core/retry.py in retry_wrapped_func(*args, **kwargs)
259 self._deadline,
--> 260 on_error=on_error,
261 )
~/anaconda3/lib/python3.6/site-packages/google/api_core/retry.py in retry_target(target, predicate, sleep_generator, deadline, on_error)
176 try:
--> 177 return target()
178
~/anaconda3/lib/python3.6/site-packages/google/api_core/future/polling.py in _done_or_raise(self)
72 """Check if the future is done and raise if it's not."""
---> 73 if not self.done():
74 raise _OperationNotComplete()
~/anaconda3/lib/python3.6/site-packages/google/cloud/bigquery/job.py in done(self, retry)
2604 project=self.project, timeout_ms=timeout_ms,
-> 2605 location=self.location)
2606
~/anaconda3/lib/python3.6/site-packages/google/cloud/bigquery/client.py in _get_query_results(self, job_id, retry, project, timeout_ms, location)
578 resource = self._call_api(
--> 579 retry, method='GET', path=path, query_params=extra_params)
580 return _QueryResults.from_api_repr(resource)
~/anaconda3/lib/python3.6/site-packages/google/cloud/bigquery/client.py in _call_api(self, retry, **kwargs)
330 call = retry(call)
--> 331 return call()
332
~/anaconda3/lib/python3.6/site-packages/google/api_core/retry.py in retry_wrapped_func(*args, **kwargs)
259 self._deadline,
--> 260 on_error=on_error,
261 )
~/anaconda3/lib/python3.6/site-packages/google/api_core/retry.py in retry_target(target, predicate, sleep_generator, deadline, on_error)
176 try:
--> 177 return target()
178
~/anaconda3/lib/python3.6/site-packages/google/cloud/_http.py in api_request(self, method, path, query_params, data, content_type, headers, api_base_url, api_version, expect_json, _target_object)
292 if not 200 <= response.status_code < 300:
--> 293 raise exceptions.from_http_response(response)
294
NotFound: 404 GET https://www.googleapis.com/bigquery/v2/projects/[project name]/queries/1e2d0ee4-2f19-440e-82e3-03b1bae0b52e?maxResults=0&timeoutMs=900: Not found: Job [project name]:1e2d0ee4-2f19-440e-82e3-03b1bae0b52e
During handling of the above exception, another exception occurred:
GenericGBQException Traceback (most recent call last)
<ipython-input-7-7eeeaffb25d8> in <module>()
1 query = "Select * FROM sample_tbl.my_data"
----> 2 data_frame = pd.read_gbq(query, '[project name]', private_key="[path for key]", dialect='standard')
3 print(data_frame)
~/anaconda3/lib/python3.6/site-packages/pandas/io/gbq.py in read_gbq(query, project_id, index_col, col_order, reauth, verbose, private_key, dialect, **kwargs)
106 private_key=private_key,
107 dialect=dialect,
--> 108 **kwargs)
109
110
~/anaconda3/lib/python3.6/site-packages/pandas_gbq/gbq.py in read_gbq(query, project_id, index_col, col_order, reauth, private_key, auth_local_webserver, dialect, location, configuration, verbose)
577 project_id, reauth=reauth, private_key=private_key, dialect=dialect,
578 auth_local_webserver=auth_local_webserver, location=location)
--> 579 schema, rows = connector.run_query(query, configuration=configuration)
580 final_df = _parse_data(schema, rows)
581
~/anaconda3/lib/python3.6/site-packages/pandas_gbq/gbq.py in run_query(self, query, **kwargs)
280 pass
281 except self.http_error as ex:
--> 282 self.process_http_error(ex)
283
284 if query_reply.cache_hit:
~/anaconda3/lib/python3.6/site-packages/pandas_gbq/gbq.py in process_http_error(ex)
214 # <https://cloud.google.com/bigquery/troubleshooting-errors>`__
215
--> 216 raise GenericGBQException("Reason: {0}".format(ex))
217
218 def run_query(self, query, **kwargs):
GenericGBQException: Reason: 404 GET https://www.googleapis.com/bigquery/v2/projects/[project name]/queries/1e2d0ee4-2f19-440e-82e3-03b1bae0b52e?maxResults=0&timeoutMs=900: Not found: Job [project name]:1e2d0ee4-2f19-440e-82e3-03b1bae0b52e
How to solve
The reason this issue occurred is setting of location.
specify geographical location of table in pandas read_gbq
To set location, we have to use pandas-gbq as caller.
Conda
$ conda install pandas-gbq --channel conda-forge
Pip
$ pip install pandas-gbq -U
The code which works
import pandas_gbq
query = "Select * FROM sample_tbl.my_data"
df = pandas_gbq.read_gbq(query=query, project_id='[project name]', dialect='standard',private_key="[path for key]", location='asia-northeast1')
Refs
specify geographical location of table in pandas read_gbq
pandas-gbq