python - TypeError: initial_value must be str or None, not bytes (bigquery) -
i'm using python3.5 , create bigquery client via bigquery using python ( https://github.com/tylertreat/bigquery-python )
here code:
from bigquery import get_client project_id = 'api-project-xxxxxx' service_account = 'xxxx@api-project-xxxx.iam.gserviceaccount.com' private_key_path = 'xxxx.p12' open(private_key_path, 'rb') f: private_key = f.read() client = get_client(project_id,private_key=private_key,service_account=service_account,readonly=true) i got below error:
--------------------------------------------------------------------------- typeerror traceback (most recent call last) <ipython-input-181-858afcfa416a> in <module>() ----> 1 client = get_client(project_id,private_key=private_key,service_account=service_account,readonly=true) /users/xxxxxx/.pyenv/versions/anaconda3-2.4.0/lib/python3.5/site-packages/bigquery/client.py in get_client(project_id, credentials, service_url, service_account, private_key, private_key_file, json_key, json_key_file, readonly, swallow_results) 131 credentials = _credentials().from_p12_keyfile_buffer( 132 service_account, --> 133 stringio(private_key), 134 scopes=scope) 135 typeerror: initial_value must str or none, not bytes
stringio converts str object stream. need pass str, private_key bytes object, because reading file in binary mode. try this:
with open(private_key_path, 'r') f: private_key = f.read() the rest of code remains same.
Comments
Post a Comment