import requests

# client_id 为官网获取的AK, client_secret 为官网获取的SK
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=hIkC0fSxfQX17dGsbVcUGYzx&client_secret=wluN6dVLGjUlnyvxtiSzQzchrHnv4O2K'
response = requests.get(host)
if response:
    text_dict = response.json()
    access_token = text_dict['access_token']
    print(access_token)

url = 'https://aip.baidubce.com/rpc/2.0/unit/bot/chat?access_token=' + access_token
post_data = "{\"bot_session\":\"\",\"log_id\":\"7758521\",\"request\":{\"bernard_level\":1,\"client_session\":\"{\\\"client_results\\\":\\\"\\\", \\\"candidate_options\\\":[]}\",\"query\":\"格力空调价格怎么样?\",\"query_info\":{\"asr_candidates\":[],\"source\":\"KEYBOARD\",\"type\":\"TEXT\"},\"updates\":\"\",\"user_id\":\"88888\"},\"bot_id\":\"1042747\",\"version\":\"2.0\"}".encode("utf-8")
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(url, data=post_data, headers=headers)
if response:
    print (response.json())

  

相关文章:

  • 2021-10-06
  • 2021-06-22
  • 2021-12-04
  • 2021-09-29
  • 2021-12-31
  • 2021-08-17
  • 2021-12-12
猜你喜欢
  • 2022-01-09
  • 2021-05-21
  • 2021-07-25
  • 2021-09-09
  • 2022-01-01
  • 2021-06-01
相关资源
相似解决方案