Search code examples
pythonasync-awaitaiohttp

How to fix TypeError: object str can't be used in 'await' expression?


Running the following code:

async def generate_url(self, ding_id):
    data = await self.s3.generate_presigned_url(
        ClientMethod='get_object',
        Params={
        'Bucket': '...',
        'Key': '{}.mp4'.format(ding_id)
        }
    )

    return data

def convert_to_json(self, data):
    loop = asyncio.get_event_loop()
    for ding in dings:
        tasks.append(self.generate_url(ding))

    video_ids = loop.run_until_complete(asyncio.gather(*tasks))
    loop.close()

causes error:

'Key': '{}.mp4'.format(ding_id) 
TypeError: object str can't be used in 'await' expression`

I use an async request library aiohttp. How to fix that problem?


Solution

  • The generate_presigned_url method is synchronous and simply returns the URL, you don't need to use await here.