错误:无法访问主机:“api.twilio.com" [英] Error: Unable to reach host: "api.twilio.com"

查看:46
本文介绍了错误:无法访问主机:“api.twilio.com"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 node-twilio 并且我不断收到 错误:无法访问主机:api.twilio.com" 对于每个请求.我们已经通过 mtr 并且他们正在访问 api.twilio.com.在 GCE 上的 debian 上运行.

I'm using node-twilio and I keep getting a "Error: Unable to reach host: "api.twilio.com" for every request. We've checked the packets via mtr and they are reaching api.twilio.com. Running on debian on GCE.

推荐答案

折腾了几天,发现 node-twilio 模块显示很多错误如下:

After days of digging around, found out that the node-twilio module shows many errors incorrectly as:

错误:无法访问主机:api.twilio.com".

"Error: Unable to reach host: "api.twilio.com".

以下几行:

var error = null;
if (err || (response && (response.statusCode < 200 || response.statusCode > 206))) {
    error = {};
    // response is null if server is unreachable
    if (response) {
        error.status = response.statusCode;
        error.message = data ? data.message : 'Unable to complete HTTP request';
        error.code = data && data.code;
        error.moreInfo = data && data.more_info;
    } else {
        error.status = err.code;
        error.message = 'Unable to reach host: "'+client.host+'"';
    }
}

发生这种情况是因为您的链中有一个自签名证书,而 twilio 依赖的底层模块是 request,它抛出以下错误:错误:SELF_SIGNED_CERT_IN_CHAIN 但这不是 node-twilio 抛出的错误(他们的错误传播错误)

This happens because you have a self signed certificate in your chain and the underlying module twilio depends on is request, which is throwing the following error: Error: SELF_SIGNED_CERT_IN_CHAIN but this is not the error being thrown by node-twilio (bad error propagation on their part)

有 2 个修复:

1.通过设置告诉 nodejs 忽略链中的自签名证书:

1.Tell nodejs to ignore self signed certificates in chain by setting:

导出 NODE_TLS_REJECT_UNAUTHORIZED=0

  1. 找到自签名证书并将其从链中删除.这是使用 openssl 的示例:https://serverfault.com/questions/590870/how-to-view-all-ssl-certificates-in-a-bundle

参考文献:

https://github.com/request/request

https://github.com/twilio/twilio-node/blob/45858420688854494c2ed476a1997773c33a32a0/lib/Client.js

忽略无效的自签名带有 https.request 的 node.js 中的 ssl 证书?

这篇关于错误:无法访问主机:“api.twilio.com"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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