Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth error when running in Cloud Functions: "'generator' object has no attribute 'headers'" #74

Closed
starmandeluxe opened this issue Oct 11, 2021 · 5 comments

Comments

@starmandeluxe
Copy link

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.

@omarryhan
Copy link
Owner

I think you should spread them:

aiogoogle.as_service_account(*delete_requests)

@starmandeluxe
Copy link
Author

starmandeluxe commented Oct 11, 2021

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?

@omarryhan
Copy link
Owner

After object=filename, can you pass validate=True

@starmandeluxe
Copy link
Author

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!!

@Ahsoka
Copy link

Ahsoka commented Oct 11, 2021

(argh, thanks Python for not being strongly typed...grrr).

If you want to check for the correct types you could use mypy. But unfortunately, I don't think this library is typed at the moment, hence it does not support mypy, see #16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants