Error: Unable to reach host: “api.twilio.com”

删除回忆录丶 提交于 2020-01-02 10:59:33

问题


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.


回答1:


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

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

The following lines:

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+'"';
    }
}

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)

There are 2 fixes:

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

export NODE_TLS_REJECT_UNAUTHORIZED=0

  1. Find the self signed certificate and remove it from the chain. Here is an example using openssl: https://serverfault.com/questions/590870/how-to-view-all-ssl-certificates-in-a-bundle

References:

https://github.com/request/request

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

Ignore invalid self-signed ssl certificate in node.js with https.request?



来源:https://stackoverflow.com/questions/37097418/error-unable-to-reach-host-api-twilio-com

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!