• googletrans 报错解决方法【httpcore,JSONDecodeError】


    googletrans json.decoder.JSONDecodeError: Extra data:
    httpcore._exceptions.ConnectTimeout: timed out

    完成以下两步:
    1.使用 pip install google_trans_new https://blog.csdn.net/a1397852386/article/details/111479024 2.手动修改google_trans_new库一行代码 https://stackoverflow.com/questions/68214591/python-google-trans-new-translate-raises-error-jsondecodeerror-extra-data Change line 151 in google_trans_new/google_trans_new.py which is: response = (decoded_line + ']') to response = decoded_line # 首先初始化2条正样本语句,和两条负样本语句 p_sample1 = "酒店设施非常不错" p_sample2 = "这家价格便宜" n_sample1 = "拖鞋都发霉了,太差了" n_sample2 = "电视不好用,没有看到足球" # # 导入google翻译接口工具 # from googletrans import Translator # # 实例化翻译对象 # translator = Translator() # # # 先进行中文到韩文的翻译 # translations = translator.translate([p_sample1,p_sample2,n_sample1,n_sample2],dest='ko') # # # 获得翻译成韩文后的文本结果 # ko_result = list(map(lambda x: x.text, translations)) # # print("中间翻译结果韩文是:") # print(ko_result) # # # 接下来进行回译 # translations = translator.translate(ko_result,dest='zh-cn') # cn_result = list(map(lambda x: x.text,translations)) # print("回译得到的增强中文文本是:") # print(cn_result) from google_trans_new import google_translator # 实例化翻译对象 translator = google_translator(timeout=10) print([p_sample1,p_sample2,n_sample1,n_sample2]) translations = [] # 先进行中文到韩文的翻译 for text in [p_sample1,p_sample2,n_sample1,n_sample2]: translations.append(translator.translate(text, 'ko')) # 获得翻译成韩文后的文本结果 ko_result = translations print("中间翻译结果韩文是:") print(ko_result) # 接下来进行回译 translations = translator.translate(ko_result,'zh-cn') cn_result = translations print("回译得到的增强中文文本是:") print(cn_result)

      

  • 相关阅读:
    [题解]luogu_P4198_楼房重建(线段树logn合并
    [题解]luogu_P3084(单调队列dp
    [题解]luogu_P3084(差分约束/梦想spfa
    [题解/模板]POJ_1201(差分约束
    [题解]luogu_P5059(矩乘
    [题解]luogu_P5004跳房子2(矩乘递推
    CF1042A Benches(二分答案)
    8.24考试总结
    NOIP2017题目
    「LG3045」「USACO12FEB」牛券Cow Coupons
  • 原文地址:https://www.cnblogs.com/xhzd/p/16021259.html
Copyright © 2020-2023  润新知