Skip to main content

Open Audio File Attachment URL in Python

  • May 2, 2023
  • 0 replies
  • 7 views

Forum|alt.badge.img

Hello!

I am trying to open an airtable attachment (m4a file) in Python but the attachment url does not have a filename. Thus, I am unable to open it.

 

import requests base_id = base_id table_name = table_name url = "https://api.airtable.com/v0/" + base_id + "/" + table_name headers = {'Authorization': 'Bearer API_KEY'} params = {"maxRecords" : 50} response = requests.get(url, params = params, headers=headers) airtable_response = response.json() fields = airtable_response['records'][0]['fields'] url = fields['Recording'][0]['url'] filename = fields['Recording'][0]['filename'] r = requests.get(url, allow_redirects=True) file = open(filename,'rb').write(r.content)