gpt4 book ai didi

node.js - 请求 API 失败,原因 : unable to verify the first certificate (and UNABLE_TO_VERIFY_LEAF_SIGNATURE)

转载 作者:行者123 更新时间:2023-12-04 22:43:19 25 4
gpt4 key购买 nike

我们有一个 Apollo 服务器,它正在调用一个外部 API(它将 REST API 转换为 GraphQL)。直到几天前,使用 cross-fetch 这一切都很好。调用 API。
星期五,我们开始收到以下错误(下)。我做了一些搜索,似乎与证书有关(例如,参见 Error: unable to verify the first certificate in nodejs)。根据该问题的答案,我尝试使用 https://www.npmjs.com/package/ssl-root-cas并把

require('https').globalAgent.options.ca = require('ssl-root-cas/latest').create();
在我的代码开始时,但这似乎不起作用。
更重要的是,我不清楚我在做什么。我对证书是什么、它们如何工作有一个大致的了解,但在这种情况下,我不清楚为什么我必须向几天前不想要的公共(public) API 提供证书。换句话说,虽然我想解决它,但我也想了解这里发生了什么。
{
"errors": [
{
"message": "request to https://www.someapi.com failed, reason: unable to verify the first certificate",
"locations": [],
"path": [
"someSearch"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"message": "request to https://www.someapi.com failed, reason: unable to verify the first certificate",
"type": "system",
"errno": "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
"code": "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
"stacktrace": [
"FetchError: request to https://www.someapi.com failed, reason: unable to verify the first certificate",
" at ClientRequest.<anonymous> (/Users/abc/Documents/projects/yaa-interface-new/node_modules/node-fetch/lib/index.js:1455:11)",
" at ClientRequest.emit (events.js:210:5)",
" at TLSSocket.socketErrorListener (_http_client.js:406:9)",
" at TLSSocket.emit (events.js:210:5)",
" at emitErrorNT (internal/streams/destroy.js:92:8)",
" at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)",
" at processTicksAndRejections (internal/process/task_queues.js:80:21)"
]
}
}
}
],
"data": {
"someSearch": null
}
}

最佳答案

我能够让这个工作 -

首先我下载了​​链 PEM 证书,灵感来自这里的第四个答案:Unable to verify leaf signature .

然后我用了NODE_EXTRA_CA_CERTS ,指向下载的 PEM 文件。
NODE_EXTRA_CA_CERTS='./something-chain.pem' node index.js
那工作得很好。

关于node.js - 请求 API 失败,原因 : unable to verify the first certificate (and UNABLE_TO_VERIFY_LEAF_SIGNATURE),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62147046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com