1

我一直在尝试按照 Zoom网站上的说明进行操作,但每次尝试发送字幕时都会收到 400 错误。

{"timestamp":1594640701018,"status":400,"error":"Bad Request","message":"No message available","path":"/closedcaption"}

文档说会议尚未开始时返回 400,但在我的测试场景中,我有两台设备连接到会议,我正在从主机复制隐藏式字幕 API 令牌,然后将其提供给我的测试程序. 据我所知,这是一个开始的会议,所以肯定还有其他事情。我已经尝试多次发送请求,但仍然收到 400 个错误。

我正在使用 Python 3,并且我都尝试过urllib.requestand http.client,但无济于事。我错过了什么?

    import urllib.request
    import http.client
    third_party_api_token = input('Third Party CC Token: ')
    domain = third_party_api_token.split('/')[2]
    if 'https://' in third_party_api_token:
        domain = domain + ':443'
    else:
        domain = domain + ':80'
    seq = 1
    while True:
        input('Press Enter to continue')
        
        formatted_url = '{}&lang=en-US&seq={}'.format(zoom_cc_url, seq)
        # formatted_text = 'Hello World\n'.encode('utf-8')
        formatted_text = 'Hello World\n'    
        headers = {'Content-Type':'text/plain'}
        print(domain)
        print(formatted_url)
        try:
            # r = urllib.request.Request(formatted_url, data=formatted_text, headers=headers, method='POST')
            # with urllib.request.urlopen(r) as response:
            #     print(response.read().decode('utf-8'))
            
            conn = http.client.HTTPSConnection(domain)
            conn.request("POST", formatted_url.replace(domain, ''), body=formatted_text, headers=headers)
            res = conn.getresponse()
            data = res.read()
            print(data.decode("utf-8"))
        except Exception as e:
            print(e)
        seq += 1
4

1 回答 1

0

在代码中留下一个旧变量名,当我删除它时工作正常。作为参考,以下代码有效:

import urllib.request
import http.client
third_party_api_token = input('Third Party CC Token: ')
domain = third_party_api_token.split('/')[2]
if 'https://' in third_party_api_token:
    domain = domain + ':443'
else:
    domain = domain + ':80'
seq = 1
while True:
    input('Press Enter to continue')
    
    formatted_url = '{}&lang=en-US&seq={}'.format(third_party_api_token , seq)
    # formatted_text = 'Hello World\n'.encode('utf-8')
    formatted_text = 'Hello World\n'    
    headers = {'Content-Type':'text/plain'}
    print(domain)
    print(formatted_url)
    try:
        # r = urllib.request.Request(formatted_url, data=formatted_text, headers=headers, method='POST')
        # with urllib.request.urlopen(r) as response:
        #     print(response.read().decode('utf-8'))
        
        conn = http.client.HTTPSConnection(domain)
        conn.request("POST", formatted_url.replace(domain, ''), body=formatted_text, headers=headers)
        res = conn.getresponse()
        data = res.read()
        print(data.decode("utf-8"))
    except Exception as e:
        print(e)
    seq += 1
于 2020-07-13T12:32:08.123 回答