最近一直在调试谷歌翻译的api,根据前两篇的相关文章,在本地的windows系统和Linux系统都配置好了环境变量和代理。剩下的就是运行代码实现翻译。windows下的很顺利直接拿谷歌提供的demo就能够编译运行。但是linux的下,同样的代码就是一直不通,运行后一直报下面的错误。
TranslateException: Error getting access token for service account: Connection reset。
其实报的就是获取认证失败。没有走设置的代理ip,那么解决方法就是在代码中指定ip和端口号。
将下面四段代码放在调用翻译之前,把自己的ip和端口号更改了就能使用了。
System.setProperty(“proxyType”, “4”); // 设置代理类型,4应该是指http
System.setProperty(“proxyPort”, “1080”); // 设置代理的端口号
System.setProperty(“proxyHost”, “192.168.1.123”); // 设置代理的ip地址
System.setProperty(“proxySet”, “true”); // 使代理生效

下面是报错的提示,如果你也提示下面的,可以尝试下上面的解决方案。也可以直接跟我留言,分享一下调试的经验。
欢迎使用google翻译!
Exception in thread “main” com.google.cloud.translate.TranslateException: Error getting access token for service account: Connection reset
at com.google.cloud.translate.spi.v2.HttpTranslateRpc.translate(HttpTranslateRpc.java:62)
at com.google.cloud.translate.spi.v2.HttpTranslateRpc.translate(HttpTranslateRpc.java:156)
at com.google.cloud.translate.TranslateImpl$4.call(TranslateImpl.java:124)
at com.google.cloud.translate.TranslateImpl$4.call(TranslateImpl.java:121)
at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105)
at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
at com.google.cloud.translate.TranslateImpl.translate(TranslateImpl.java:120)
at com.google.cloud.translate.TranslateImpl.translate(TranslateImpl.java:138)
at GoogleTranslationUtil.main(GoogleTranslationUtil.java:20)
Caused by: java.io.IOException: Error getting access token for service account: Connection reset
at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:432)
at com.google.auth.oauth2.OAuth2Credentials.refresh(OAuth2Credentials.java:157)
at com.google.auth.oauth2.OAuth2Credentials.getRequestMetadata(OAuth2Credentials.java:145)
at com.google.auth.http.HttpCredentialsAdapter.initialize(HttpCredentialsAdapter.java:91)
at com.google.cloud.http.HttpTransportOptions$1.initialize(HttpTransportOptions.java:159)
at com.google.api.client.http.HttpRequestFactory.buildRequest(HttpRequestFactory.java:88)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.buildHttpRequest(AbstractGoogleClientRequest.java:430)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:549)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:482)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:599)
at com.google.cloud.translate.spi.v2.HttpTranslateRpc.translate(HttpTranslateRpc.java:142)
… 8 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1334)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1309)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:259)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:108)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:79)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:995)
at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:429)

解决谷歌翻译TranslateException: Error getting access token for service account: Connection reset相关推荐

  1. 解决shell脚本“syntax error near unexpected token `fi‘”的问题。

    解决shell脚本"syntax error near unexpected token `fi'"的问题. 参考文章: (1)解决shell脚本"syntax erro ...

  2. 插件自动解决谷歌翻译用不了,win、mac、linux通用,附链接

    插件自动解决谷歌翻译用不了,支持win.mac.linux附链接: 文件地址: win:https://wwt.lanzouy.com/iJsx20fzvumj mac:https://wwt.lan ...

  3. 【Git】解决remote: ******: Incorrect username or password (access token)方法

    remote: ******: Incorrect username or password (access token) 解决方法: 控制面板--账号管理-- 修改正确的gitee账号密码

  4. 解决谷歌翻译不能用的方法

    解决方法其实也很简单,只需要通过 hosts 把谷歌翻译的 API 指向国内可用服务器地址即可. 2022.10.24 更新:最近自己 ping 出来的 ip 可能不能用了,可以用下面 ip 试下: ...

  5. 解决谷歌翻译不能使用的问题(2023.01.14)

    今天登录国外网站,发现谷歌翻译已无法正常使用,网上最多的方法就是更改host文件,在host内增加ip地址,亲测管用,但是经常失效,经常手动更改增加ip着实烦恼,于是登录GitHub后找到Ponder ...

  6. 解决谷歌翻译不能使用的方法

    目录 一.需要通过 hosts 把谷歌翻译的 API 指向国内可用服务器地址. 步骤1:查找可用服务器地址 步骤2:修改 hosts 文档 Mac编辑文件保存遇到E45: 'readonly' opt ...

  7. Windows系统解决谷歌翻译不能用的问题

    最近在使用谷歌浏览器(Chrome)的时候,点击右键翻译,一直都给我提示页面无法翻译, 从网上查阅资料才了解到了谷歌关闭了中国大陆的谷歌翻译服务,同时也找到了解决这个问题的方法. 第一步:查找可用的服 ...

  8. immersive-translate(沉浸式双语网页翻译扩展),解决谷歌翻译无法使用问题

    前言 谷歌停止了大陆的谷歌翻译服务,所以找到了immersive-translate 插件解决翻译问题.当然 最直接就是 换个浏览器比如 Edge\Firefox等等. 主要特性 智能识别网页主内容区 ...

  9. 小知识(3) 解决谷歌翻译问题(浏览器/IDEA)

    一.问题 谷歌浏览器中的翻译无法使用 IDEA中Translation插件无法正常翻译 二.解决 修改 C:\Windows\System32\drivers\etc\hosts # 解决 idea ...

最新文章

  1. 软件测试测试人员遇到的问题及解决方法(面试)
  2. 深度学习生态圈【详解深度学习工具Keras】
  3. PostMessage()和SendMessage()
  4. python有趣代码-一个有意思的 Python 训练项目集
  5. 计算机组装方案及分析,《计算机组装与维护》课程整体教学方案
  6. 干掉 Swagger,试试这个!
  7. spring本地化默认英文_Spring3国际化和本地化
  8. 余承东:华为自研的麒麟A1芯片已经应用在了多款可穿戴产品中
  9. linux mysql emoji_Linux宝塔面板MySQL存储emoji,非服务器命令方法
  10. 在.h文件和.m文件里使用import指令有何区别?
  11. 2017年10月、11月 windows 用360 打最新补丁导致的问题
  12. 英语视听说第六版答案
  13. 图的应用--最小生成树
  14. 应广单片机mini-c中用指针实现数组数功能
  15. ERP系统中BOM的作用
  16. 苹果手机尺寸详细表及iPhoneX、iPhoneXS、iPhoneXR、iPhoneXSMax、iPhone 11、iPhone 11 Pro、iPhone 11 Pro Max、屏幕适配
  17. 科学计算机怎么算锥度,如何计算锥度值?比如说1:20等于多少度?请说说具体步骤!-锥度的计算公式-数学-贾儆刹同学...
  18. 锐角三角函数怎么用计算机算,锐角三角函数:运用计算器
  19. echarts 百万数据_GitHub - AricZhu/echarts-billion-data-disp: 针对 echarts 百万数据的折线图优化...
  20. 继电器为何要并联二极管使用

热门文章

  1. AI开发者大会:2020年7月3日09:10--09:30张钹《人工智能的发展现状与人才培养》
  2. RV1126新增驱动IMX415 SENSOR,实现v4l2抓图
  3. 标 题: 台资企业一般怎么样啊
  4. ai域名在哪里注册?
  5. java 图片签章(颜色像素)提取并优化
  6. ALI Flutter进阶笔记
  7. 字符串拼接后分割再去重java_oracle 一个字段去重得到不重复航司
  8. elasticsearch启动报错Failed to clear cache for realms [[]]
  9. android github 多页面程序,论一个APP从启动到主页面显示经历的过程?
  10. 通过QQ邮箱反查QQ号