|
5 | 5 | import uuid
|
6 | 6 | import time
|
7 | 7 | import sys
|
| 8 | +import os |
8 | 9 |
|
9 | 10 | import numpy as np
|
10 | 11 |
|
@@ -279,7 +280,7 @@ def load_user_account_credentials(self):
|
279 | 280 | from google.oauth2.credentials import Credentials
|
280 | 281 |
|
281 | 282 | try:
|
282 |
| - with open('bigquery_credentials.dat') as credentials_file: |
| 283 | + with open(_get_credentials_file()) as credentials_file: |
283 | 284 | credentials_json = json.load(credentials_file)
|
284 | 285 | except (IOError, ValueError):
|
285 | 286 | return None
|
@@ -307,7 +308,7 @@ def save_user_account_credentials(self, credentials):
|
307 | 308 | .. versionadded 0.2.0
|
308 | 309 | """
|
309 | 310 | try:
|
310 |
| - with open('bigquery_credentials.dat', 'w') as credentials_file: |
| 311 | + with open(_get_credentials_file(), 'w') as credentials_file: |
311 | 312 | credentials_json = {
|
312 | 313 | 'refresh_token': credentials.refresh_token,
|
313 | 314 | 'id_token': credentials.id_token,
|
@@ -790,6 +791,11 @@ def delete_and_recreate_table(self, dataset_id, table_id, table_schema):
|
790 | 791 | sleep(delay)
|
791 | 792 |
|
792 | 793 |
|
| 794 | +def _get_credentials_file(): |
| 795 | + return os.environ.get( |
| 796 | + 'PANDAS_GBQ_CREDENTIALS_FILE', 'bigquery_credentials.dat') |
| 797 | + |
| 798 | + |
793 | 799 | def _parse_data(schema, rows):
|
794 | 800 | # see:
|
795 | 801 | # http://pandas.pydata.org/pandas-docs/dev/missing_data.html
|
@@ -875,7 +881,10 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
|
875 | 881 | authentication (eg. jupyter iPython notebook on remote host)
|
876 | 882 | auth_local_webserver : boolean, default False
|
877 | 883 | Use the [local webserver flow] instead of the [console flow] when
|
878 |
| - getting user credentials. |
| 884 | + getting user credentials. A file named bigquery_credentials.dat will |
| 885 | + be created in current dir. You can also set PANDAS_GBQ_CREDENTIALS_FILE |
| 886 | + environment variable so as to define a specific path to store this |
| 887 | + credential (eg. /etc/keys/bigquery.dat). |
879 | 888 |
|
880 | 889 | .. [local webserver flow]
|
881 | 890 | http://google-auth-oauthlib.readthedocs.io/en/latest/reference/google_auth_oauthlib.flow.html#google_auth_oauthlib.flow.InstalledAppFlow.run_local_server
|
|
0 commit comments