Help

Open Audio File Attachment URL in Python

Topic Labels: Scripting
493 0
cancel
Showing results for 
Search instead for 
Did you mean: 
evanlord
4 - Data Explorer
4 - Data Explorer

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)

 

0 Replies 0