client.get_bucket() returns error: api_request() got an unexpected keyword argument 'extra_api_info'


I’m trying to store a newline-delimited JSON string in a GCS bucket using a cloud function, but seeing an error. I start by converting a dataframe to ndjson, then attempt to upload this to my GCS bucket as below. There is more code above this, but not relevant to my problem:

import pandas as pd
from import storage
from import blob

df = df.to_json(orient="records", lines=True)

storage_client = storage.Client(project='my-project')
bucket = storage_client.get_bucket('my-bucket')
blob = bucket.blob('my-blob')

When running this, I find the error below in the logs:

Exception on / [POST] Traceback (most recent call last): 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/flask/", line 2073, in wsgi_app response = self.full_dispatch_request() 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/flask/", line 1518, in full_dispatch_request rv = self.handle_user_exception(e) 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/flask/", line 1516, in full_dispatch_request rv = self.dispatch_request() 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/flask/", line 1502, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/functions_framework/", line 99, in view_func return function(request._get_current_object()) 
File "/workspace/", line 66, in my_request bucket = storage_client.get_bucket('my-bucket') 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/storage/", line 787, in get_bucket retry=retry, 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/storage/", line 1037, in reload retry=retry, 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/storage/", line 244, in reload _target_object=self, 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/storage/", line 373, in _get_resource _target_object=_target_object, 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/storage/", line 73, in api_request return call() 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/api_core/", line 288, in retry_wrapped_func on_error=on_error, 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/api_core/", line 190, in retry_target return target() TypeError: api_request() got an unexpected keyword argument 'extra_api_info'

This ‘extra_api_info’ argument appears to be the culprit, but I have no idea what this means, and never used to get this error when following exactly the same approach, so I wonder whether this is down to some change between different versions of the ‘’ Python module.


I worked out the answer to my own question. It was indeed a module version issue as I suspected.

Specifying in my requirements.txt file solved the problem, as my code is seemingly not compatible with the latest version of that module (for reasons that escape me).

Answered By – hawkaterrier

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published