LingQをより快適にするためCookieを使用しています。サイトの訪問により同意したと見なされます cookie policy.

ca   カナダ

Python - uploading audio via API

August 2019

There was never an answer for the last post on this thread:

How do upload audio?

How do we resolve the "The submitted data was not a file. Check the encoding type on the form." error message?

My script thus far:

# this is in my .env file: #APIKey = "[the access code from ]" #mp3DIR = "/Users/paulgamble/Desktop/mp3splitter-js/test.mp3" #status = "private" #collectionID = "495095" import requests import os from dotenv import load_dotenv load_dotenv() key = os.getenv("APIKey") mp3DIR = os.getenv("mp3DIR") status = os.getenv("status") collectionID = os.getenv("collectionID") def printenvironment(): print(f'The API key is: {key}') print(f'The mp3 dir is: {mp3DIR}') if __name__ == "__main__": printenvironment() data = {"title": "Lorem Ipsum", "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut \ labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi\ ut aliquip ex ea commodo consequat.", "status": status, "tags": ["Test"], "collection": collectionID, "audio": mp3DIR } response = requests.post('https://www.lingq.com/api/v2/fr/lessons/', data=data, headers={'Authorization': 'Token ' + key}) print(response.status_code) print(response.text) # THIS IS THE OUTPUT: # The API key is: d57b6431d575db71fc754b5e5527dd2e422a2f94 # The mp3 dir is: / Users/paulgamble/Desktop/mp3splitter-js/test.mp3 # 400 #{"audio": ["The submitted data was not a file. Check the encoding type on the form."]}