首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么我在腾讯会议API中不断收到错误代码400?

为什么我在腾讯会议API中不断收到错误代码400?

提问于 2020-05-18 16:29:05
回答 1关注 0查看 622

我不断收到错误代码400:“不受支持的REST API”。我的hmac246 base64编码签名是正确的,因为我已经用php中的另一个工作代码示例对其进行了测试。有人可以帮我解决问题吗?我正在使用python。

这是最终的输出.

这是输出http标头.

代码语言:js
复制
{'Content-Length': '0', 'Accept-Encoding': 'gzip, deflate', 'X-TC-Timestamp': '1589787785', 'X-TC-Nonce': '243222', 'User-Agent': 'python-requests/2.23.0', 'X-TC-Key': 'xxx', 'Connection': 'keep-alive', 'Accept': 'application/json', 'AppId': '200000164', 'content-type': 'application/json', 'X-TC-Signature': 'ZmUzYjg4ZjRlNTIwYTRiYTlhZGY3YTVhMzBiZGU4YjM3MDBhYWRmMmQ4OGJkYWE1NWQ2NmIzMjQ2ODQyNDkyNQ=='}

这是创建会议的发帖请求。

代码语言:js
复制
def add(start,end):

    uri = '/v1/meetings'
    userid = User.id
    settings = {
            "mute_enable_join" : True,
            "allow_unmute_self" : True,
            "mute_all" : False,
            "host_video" : False,
            "participant_video" : False,
            "enable_record" : False,
            "play_ivr_on_leave" : False,
            "play_ivr_on_join" : False,
            "live_url" : False
    }
    params = {'userid':userid,'instanceid': 5,
              'subject':'consultation','type':0,
              'start_time':str(start),
              'end_time':str(end),
              'settings':str(settings)}
    headers = generateHeaders('POST',params,uri)

    response = requests.post("https://api.meeting.qq.com/v1/meetings",headers=headers,params=params)
    print(response.request.headers)
    print(response.url)
    return response.json()

这是标题生成

代码语言:js
复制
def generateHeaders(method,params,uri):
    nonce = generate_nonce()
    timeStamp = int(time.time())

    headerString = "X-TC-Key=" + SecretId + "&X-TC-Nonce=" + str(nonce) + "&X-TC-Timestamp=" + str(timeStamp)
    stringSign= method+"\n"+str(headerString)+"\n"+uri+"\n"+str(params)
    b64 = create_sign(SecretKey,stringSign)

    print('final=',b64)

    return {'X-TC-Key': SecretId,
            'X-TC-Timestamp': str(timeStamp),
            'X-TC-Nonce': str(nonce),
            'AppId': str(appID),
            'X-TC-Signature': str(b64),
            'content-type':'application/json',
            'Accept': 'application/json'}

这是签名计算功能.

代码语言:js
复制
def create_sign(key,toSign):


    h = hmac.new(key,msg=toSign.encode('utf-8'),digestmod=hashlib.sha256).hexdigest()
    print(type(h))
    print(h)
    base = base64.b64encode(h.encode('utf-8'))
    hash = base.decode('utf-8')
    return hash

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档