The SubDB ( http://thesubdb.com/api/ )を使用して、Python 3.x で自動字幕ファインダーを作成しようとしています。私は現在、アップロード機能に取り組んでいます。しかし、私はそれを機能させることができません。415 エラー (サポートされていないメディア タイプ) が発生し続けます。SubDB Web サイトでは、「リクエスト サンプル」が提供されています。
POST /?action=upload HTTP/1.1
Host: api.thesubdb.com
User-Agent: SubDB/1.0 (Pyrrot/0.1; http://github.com/jrhames/pyrrot-cli)
Content-Length: 60047
Content-Type: multipart/form-data; boundary=xYzZY
- - --xYzZY
Content-Disposition: form-data; name="hash"
edc1981d6459c6111fe36205b4aff6c2
- - --xYzZY
Content-Disposition: form-data; name="file"; filename="subtitle.srt"
Content-Type: application/octet-stream
[PAYLOAD]
しかし、これを解釈する方法がわからず、オンラインで答えを見つけることができませんでした。これは私の現在のコードです:
def uploadSubtitle(hash, path):
params = {'action': "upload", 'hash': hash}
response = requests.post(
url=base_url.format(urllib.parse.urlencode(params)),
data=open(path,'r').read(),
headers = {
'User-Agent': user_agent,
'Content-Length': 51200,
'Content-Type': "multipart/form-data; boundary=xYzZY",
'Host': "api.thesubdb.com"
}
)
return response.status_code
どんなアドバイスでも大歓迎です!