修复方法:"EPROTO"升级Node版本后出错 [英] How to fix: "EPROTO" Error after upgrading Node's version

查看:89
本文介绍了修复方法:"EPROTO"升级Node版本后出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码适用于Node的v10.15.3版本:

The following code works on Node's v10.15.3 version:

const { post } = require('request');

post({
  url: 'https://cidadao.sinesp.gov.br/sinesp-cidadao/mobile/consultar-placa/v4',
  body: '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<v:Envelope xmlns:v=\"http://schemas.xmlsoap.org/soap/envelope/\">\n  <v:Header>\n    <b>LGE Nexus 5</b>\n    <c>ANDROID</c>\n    <d>v4</d>\n    <e>4.3.2</e>\n    <f>98.193.54.223</f>\n    <g>514650d8dba4784ed08b5a029583576361a50bc5</g>\n    <h>-3272.3179572637086</h>\n    <i>940.839492700698</i>\n    <j/>\n    <k/>\n    <l>2019-05-24 10:24:35</l>\n    <m>8797e74f0d6eb7b1ff3dc114d4aa12d3</m>\n  </v:Header>\n  <v:Body xmlns:n0=\"http://soap.ws.placa.service.sinesp.serpro.gov.br/\">\n    <n0:getStatus>\n      <a>LSU3J43</a>\n    </n0:getStatus>\n  </v:Body>\n</v:Envelope>',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'User-Agent': 'SinespCidadao / 3.0.2.1 CFNetwork / 758.2.8 Darwin / 15.0.0',
    Host: 'cidadao.sinesp.gov.br'
  },
}, (err, httpResponse, body) => {
  if (err) return console.error(err);
  console.log(JSON.stringify(httpResponse));
});

但是升级到v12.2.0或更高版本后,出现以下错误:

But after upgrading to v12.2.0 or above I got the following error:

Error: write EPROTO 17432:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol:c:\ws\deps\openssl\openssl\ssl\statem\statem_lib.c:1922:

    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:83:16) {
  errno: 'EPROTO',
  code: 'EPROTO',
  syscall: 'write'
}

我该如何解决?

推荐答案

由于相同的代码可在Node.js v10.15.3上运行,但不能在v12.2.0上运行,并且错误消息表示不支持的协议"此问题的可能根本原因是:Node.js 10中受支持的最低TLS版本为TLSv1.0,但是由于v11.4.0,它被提高为TLSv1.2( api/tls.html#tls_tls_default_min_version"rel =" noreferrer> tls.DEFAULT_MIN_VERSION ).我怀疑cidadao.sinesp.gov.br的证书是使用TLSv1.0签名的,该证书可在Node.js v10.15.3上使用,但不能在v12.2.0上使用.

As the same code works on Node.js v10.15.3, but not work on v12.2.0, and the error message indicates "unsupported protocol", the most possible root cause of this issue is: the minimal supported TLS version in Node.js 10 is TLSv1.0, but since v11.4.0, it is raised to TLSv1.2 (tls.DEFAULT_MIN_VERSION). I suspect the certificate of cidadao.sinesp.gov.br is signed with TLSv1.0, which works on Node.js v10.15.3, but not on v12.2.0.

要使Node.js接受TLSv1.0,可以使用--tls-min-v1.0选项启动Node.js进程.

To make Node.js accept TLSv1.0, you can lauch Node.js process with --tls-min-v1.0 option.

我做了一个实验,效果很好:

I made an experiment and it works well:

顺便说一句,cidadao.sinesp.gov.br的证书现在无效.该请求自2018年5月起已过期-正如OP所述,该请求应从巴西发送(或通过巴西的代理节点发送).

BTW, the certificate of cidadao.sinesp.gov.br is invalid now. It has been expired since May 2018 -- as the OP mentioned, the request should be sent from Brazil (or through proxy node in Brazil).

这篇关于修复方法:"EPROTO"升级Node版本后出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆