425776024 / nlpcda

一键中文数据增强包 ; NLP数据增强、bert数据增强、EDA:pip install nlpcda

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

没有key的bug

ZeKunZhang1998 opened this issue · comments

  4 # 申请你的 appid、secretKey
  5 # 两遍洗数据法(回来的中文一般和原来不一样,要是一样,就不要了,靠运气?)

----> 6 en_s = baidu_translate(content=zh, appid='xxx', secretKey='xxx',t_from='zh', t_to='en')
7 zh_s = baidu_translate(content=en_s, appid='xxx', secretKey='xxx',t_from='en', t_to='zh')
8 print(zh_s)

/opt/conda/lib/python3.7/site-packages/nlpcda/tools/Translate.py in baidu_translate(content, appid, secretKey, t_from, t_to)
30 j = requests.get('http://api.fanyi.baidu.com/api/trans/vip/translate', head)
31 # print(j.json())
---> 32 res = j.json()['trans_result'][0]['dst']
33 # print(res)
34 return res

KeyError: 'trans_result'

这个appid='xxx', secretKey='xxx',注册了?(注册了的话看看j = requests.get('http://api.fanyi.baidu.com/api/trans/vip/translate', head)返回的有没有数据,没有自然就KeyError: 'trans_result'了)可能是api接口变了,没详细测试过

可能是标准版访问速度被限制了,中间加个time.sleep(1)
en_s = baidu_translate(content=zh, appid='', secretKey='',t_from='zh', t_to='en')
time.sleep(1)
zh_s = baidu_translate(content=en_s, appid='', secretKey='',t_from='en', t_to='zh')