Auth error when running in Cloud Functions: "'generator' object has no attribute 'headers'"
starmandeluxe opened this issue · 5 comments
I am trying to call the Cloud Storage API via aiogoogle with the intent of performing concurrent blob delete operations, but I get this error when running it via Cloud Functions:
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/aiogoogle/client.py", line 278,
in as_service_account authorized_requests = [ File "/layers/google.python.pip/pip/lib/python3.9/site-packages/aiogoogle/client.py",
line 279, in <listcomp> self.service_account_manager.authorize(request)
for request in requests File "/layers/google.python.pip/pip/lib/python3.9/site-packages/aiogoogle/auth/managers.py",
line 1182, in authorize if request.headers is None: AttributeError: 'generator' object has no attribute 'headers'
Here is my code:
aiogoogle = Aiogoogle(service_account_creds=creds)
await aiogoogle.service_account_manager.detect_default_creds_source()
async with aiogoogle:
async_storage_client = await aiogoogle.discover('storage', 'v1')
delete_requests = (
async_storage_client.objects.delete(
project=creds['project_id'],
bucket=my_bucket,
object=filename) for filename in filenames)
await aiogoogle.as_service_account(delete_requests)
What am I doing wrong? I based this off this sample code.
I think you should spread them:
aiogoogle.as_service_account(*delete_requests)
Hi @omarryhan,
Thank you very much, however that didn't seem to help. Now I get this error:
await aiogoogle.as_service_account(*delete_requests)
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/aiogoogle/client.py",
line 282, in as_service_account return await self.send( File "/layers/google.python.pip/pip/lib/python3.9/site-packages/aiogoogle/client.py",
line 366, in send return await self.active_session.send(*args, **kwargs) File "/layers/google.python.pip/pip/lib/python3.9/site-packages/aiogoogle/sessions/aiohttp_session.py",
line 172, in send results = await schedule_tasks() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/aiogoogle/sessions/aiohttp_session.py",
line 164, in schedule_tasks return await asyncio.gather(*tasks, return_exceptions=False) File "/layers/google.python.pip/pip/lib/python3.9/site-packages/aiogoogle/sessions/aiohttp_session.py",
line 150, in get_content response = await get_response(request) File "/layers/google.python.pip/pip/lib/python3.9/site-packages/aiogoogle/sessions/aiohttp_session.py",
line 146, in get_response response.raise_for_status() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/aiogoogle/models.py",
line 434, in raise_for_status raise HTTPError(msg=self.reason, req=self.req, res=self) aiogoogle.excs.HTTPError:
And below that, no error message, so I only get the exception name...any ideas?
After object=filename, can you pass validate=True
Sorry, I was able to fix the issue, it was due to an unrelated bug. Probably what you suggested would have pointed out the issue anyway, but I noticed that the filenames I tried passing in were not string types (argh, thanks Python for not being strongly typed...grrr).
So your first comment was the actual solution. Thank you so much!!