2

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

どんなアドバイスでも大歓迎です!

4

1 に答える 1

-1

私は同じ問題を抱えていました。

これを見たいと思うかもしれませんhttps://github.com/ivandrofly/SubDBSharp

以下を試してください:

    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: [Subtitle content length including boundary length]
    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

    [SUBTITLE CONTENT]
    --xYzZY


    # Content-Length:
    Content length should be from --xYzZY to last --xYzZY see above.

注: 境界は --xYzZY で始まり、[SUBTITLE CONTENT] の後に終了します

于 2016-10-21T20:42:06.413 に答える