2017-01-26 11 views
-1

私は動作することがわかっているcurlコマンドを持っています。私はそれをPythonに翻訳しようとしましたが、エラーが発生します。curlコールをPythonリクエストに変換する

具体的には、「モデル」フィールドが定義されていないという応答が返されます。フォームデータを定義する適切な方法は何ですか?

カール:

curl \ 
    -F [email protected]_audio_file.mp3 \ 
    -F model=en-US \ 
    -F 'notification=callback' \ 
    -F 'callback=http://your_url.com/transcript_callback' 
    "https://api.speechmatics.com/v1.0/user/123/jobs/?auth_token=ABC" 

のpython:

files = { 
    'data_file': open('my_audio_file.mp3', 'rb'), 
    'model': 'en-US', 
    'notification': 'callback', 
    'callback': 'http://your_url.com/transcript_callback' 
} 
requests.post('https://api.speechmatics.com/v1.0/user/123/jobs/?auth_token=ABC', files=files) 
+0

あなたはエラーの詳細特異的であった場合、それが役立つだろう:

また、正しいフォームのデータは次のようになります。 – RobertB

+0

@RobertB APIからの単なるエラーです。 'b' {\ n "code":400、\ n "error": "言語を選択していません" \ n} '' –

答えて

0

私はエラーがrequestsライブラリーに関連した決定しました。バージョン2.11.1を使用すると、この問題が修正されます。

files = { 
    'data_file': open('my_audio_file.mp3', 'rb'), 
    'model': ('', 'en-US'), 
    'notification': ('', 'callback'), 
    'callback': ('', 'http://your_url.com/transcript_callback') 
} 
関連する問題