2

我正在尝试使用 SubDB ( http://thesubdb.com/api/ ) 在 Python 3.x 中编写一个自动字幕查找器。我现在正在开发上传功能。但是,我无法让它工作。我不断收到 415 错误(不支持的媒体类型)。在 SubDB 网站上,给出了一个“请求样本”:

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 回答