Help uploading MP3s via the LingQ API

I’ve been able to create text only uploads via a python script through the LingQ API as follows:

data = {"title" : "Lorem Ipsum",
             "text" : "Lorem ipsum dolor sit amet.",
             "tags" : ["Test"]
     h = {'Authorization' : 'Token ' + API_KEY,
          'Content-Type' : 'application/json'}

     json_data = json.dumps(data)
     r ='', data=json_data, headers=h)

My current aim is to be able to upload a set of podcast mp3s for transcription. My research suggests this requires multipart encoding to send the mp3 file as well, but I can’t tell exactly what format the LingQ API backend accepts. I am following along previously working examples such as: Python - uploading audio via API - #5 by mescyn

Here’s my code:

    f = "foo.mp3"
    m = MultipartEncoder(fields={
        'title' : "Lorem Ipsum",
        'text' : "Lorem ipsum dolor sit amet.",
        'audio': (f, open(f, 'rb'), 'audio/mpeg')

    h = {'Authorization' : 'Token ' + API_KEY,
            'Content-Type' : m.content_type}
    req ='', 
                           headers=h, data=m)

This results in a 500 error:

		<title>500 - Internal server error</title>
		<style type="text/css">
	        #bd #page #content-header {
	            display: none;

Would anyone be able to help give guidance on how to get mp3 uploads working?

Try this script by user rafarafa: