评论观点抽取报错
鹿鼎记肯定 发布于2020-08 浏览:3626 回复:5
0
收藏

错误提示:

{'log_id': 4822239272727424623, 'error_code': 282004, 'error_msg': 'invalid parameter(s)'}

 

代码:

把开头的api_key和secret_key改成自己的值

import requests

API_Key = 【API Key】
Secret_Key = 【Secret_Key】

# 第一次 Post 请求,获取access_token
def get_access_token():
    # URL
    url = 'https://aip.baidubce.com/oauth/2.0/token'
    # 参数
    params = {
        'grant_type': 'client_credentials',    # 固定值  
        'client_id': API_Key,  
        'client_secret': Secret_Key  
    }
    res = requests.post(url, data=params).json()
    return res['access_token']

# # 第二次 Post 请求
url = "https://aip.baidubce.com/rpc/2.0/nlp/v2/comment_tag" + "?charset=UTF-8&access_token=" + get_access_token()
text = "环境一般般把,音响设备也一般,隔音太差".encode('utf-8')
params = {
    'text': text,
    'type': 3
}
header = {
    'content-type': 'application/json'
}
res = requests.post(url, data=params, headers=header).json()
print(res)
收藏
点赞
0
个赞
共5条回复 最后由用户已被禁言回复于2022-04
#6鹿鼎记肯定回复于2020-09
#5 一只小花猫吖回复
也有这个问题了,我随便输入一段数字字母汉字就可以,但是有的时候汉字多了以后就不可以了
展开

他的输入是有限制的,具体可以翻翻文档。

0
#5一只小花猫吖回复于2020-09

也有这个问题了,我随便输入一段数字字母汉字就可以,但是有的时候汉字多了以后就不可以了

0
#4鹿鼎记肯定回复于2020-08

已解决

1. 将text的encode('utf-8')去掉,并把url改成url = "https://aip.baidubce.com/rpc/2.0/nlp/v2/comment_tag" + "?access_token=" + get_access_token()
2. params下添加一行代码

params = json.dumps(params)
0
#3鹿鼎记肯定回复于2020-08

错误是说

请求中包含非法参数,请检查后重新尝试

不明白参数哪里有问题

0
#2鹿鼎记肯定回复于2020-08

试过其他的一些产品,都是按照这样的流程,每出过问题

0
TOP
切换版块