How to fix Stripe Error: Network error [errno 77]: error setting certificate verify locations
How to fix Stripe Error: Network error [errno 77]: error setting certificate verify locations
我正尝试在我的网站上使用 Stripe,但出现以下错误:
Fatal error:
Uncaught Stripe\Error\ApiConnection: Unexpected error communicating with Stripe. If this problem persists, let us know at support@stripe.com.
(Network error [errno 77]: error setting certificate verify locations: CAfile: CApath: /etc/ssl/certs) in /var/www/html/assets/vendor/stripe/lib/HttpClient/CurlClient.php:284
Stack trace:
#0 /var/www/html/assets/vendor/stripe/lib/HttpClient/CurlClient.php(241): Stripe\HttpClient\CurlClient->handleCurlError('https://api.str...', 77, 'error setting c...', 0)
#1 /var/www/html/assets/vendor/stripe/lib/HttpClient/CurlClient.php(203): Stripe\HttpClient\CurlClient->executeRequestWithRetries(Array, 'https://api.str...')
#2 /var/www/html/assets/vendor/stripe/lib/ApiRequestor.php(364): Stripe\HttpClient\CurlClient->request('post', 'https://api.str...', Array, Array, false)
#3 /var/www/html/assets/vendor/stripe/lib/ApiRequestor.php(96): Stripe\ApiRequestor->_requestRaw('post', '/v1/charges', Array, Array)
#4 /var/www/html/assets/vendor/stripe/lib/ApiOperations/Request.php(5 in /var/www/html/assets/vendor/stripe/lib/HttpClient/CurlClient.php on line 284
我最近使用一键 LAMP 部署在 Google Compute Engine 上创建了一个新虚拟机。我还使用 Lets Encrypt 来允许 https。此外,我已经下载了最新的 cacert.pem 文件并将其放在 /etc/ssl/certs
文件夹中。
证书文件夹具有以下权限:
drwxr-xr-x 2 root root 20480 Apr 5 14:31 certs
该文件具有以下权限:
-rw-r--r-- 1 root root 219596 Apr 5 14:29 cacert.pem
我还编辑了 php.ini
文件以将 curl.cainfo
和 openssl.cafile
指向 pem 文件并重新启动 Apache。
在查看 Stripe 的网站时,它提到现在需要 TLS 1.2。我已确认我的网站正在使用它。但是 Stripe 网站上的一些示例测试代码似乎表明它没有看到 TLS 1.2。
根据 ssllabs.com,我的站点被识别为具有 TLS 1.2 协议。
我添加到我的站点以验证的 Stripe 示例代码是:
\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
try {
\Stripe\Charge::all();
echo "TLS 1.2 supported, no action required.";
} catch (\Stripe\Error\ApiConnection $e) {
echo "TLS 1.2 is not supported. You will need to upgrade your integration.";
}
我还添加了以下内容以获取其他版本信息:
echo 'PHP version: ' . phpversion() . PHP_EOL . '<br/>';
echo 'cURL version: ' . curl_version()['version'] . PHP_EOL . '<br/>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.howsmyssl.com/a/check");
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo 'TLS version: ' . json_decode($response)->tls_version . PHP_EOL;
我运行时的结果是:
============= Stripe Suggested Test Code ============
TLS 1.2 is not supported. You will need to upgrade your integration.
================================================
==================== Version Code ===================
PHP version: 7.0.33-0+deb9u3
cURL version: 7.52.1
TLS version: TLS 1.2
================================================
在这一点上,我 运行 没有想法了。为了全面披露,我的大部分学习都是通过 Google 搜索和这个网站进行的,因此,如果您能在业余编码水平上提供任何帮助,我们将不胜感激。
所以,看着 the code 我看到了这个:
class CurlClient implements ClientInterface
{
public function request($method, $absUrl, $headers, $params, $hasFile)
{
...
$opts[CURLOPT_CAINFO] = Stripe::getCABundlePath();
...
}
}
这又将我引向 this code:
class Stripe
{
// @var string Path to the CA bundle used to verify SSL certificates
public static $caBundlePath = null;
/**
* @return string
*/
private static function getDefaultCABundlePath()
{
return realpath(dirname(__FILE__) . '/../data/ca-certificates.crt');
}
/**
* @return string
*/
public static function getCABundlePath()
{
return self::$caBundlePath ?: self::getDefaultCABundlePath();
}
/**
* @param string $caBundlePath
*/
public static function setCABundlePath($caBundlePath)
{
self::$caBundlePath = $caBundlePath;
}
}
这使得 Stripe 出于某种原因看起来不想使用系统 CA 路径。所以你可以:
- 使用
Stripe::setCABundlePath()
指向系统CA包
或
- 确保
data/ca-certificates.crt
的 CA 包(随 Stripe 一起提供)存在并且具有适当的权限。
我收到了这条错误消息。我通过重新安装 Stripe 库解决了这个问题。根本原因是 /data 目录丢失或损坏。
我正尝试在我的网站上使用 Stripe,但出现以下错误:
Fatal error:
Uncaught Stripe\Error\ApiConnection: Unexpected error communicating with Stripe. If this problem persists, let us know at support@stripe.com.
(Network error [errno 77]: error setting certificate verify locations: CAfile: CApath: /etc/ssl/certs) in /var/www/html/assets/vendor/stripe/lib/HttpClient/CurlClient.php:284
Stack trace:
#0 /var/www/html/assets/vendor/stripe/lib/HttpClient/CurlClient.php(241): Stripe\HttpClient\CurlClient->handleCurlError('https://api.str...', 77, 'error setting c...', 0)
#1 /var/www/html/assets/vendor/stripe/lib/HttpClient/CurlClient.php(203): Stripe\HttpClient\CurlClient->executeRequestWithRetries(Array, 'https://api.str...')
#2 /var/www/html/assets/vendor/stripe/lib/ApiRequestor.php(364): Stripe\HttpClient\CurlClient->request('post', 'https://api.str...', Array, Array, false)
#3 /var/www/html/assets/vendor/stripe/lib/ApiRequestor.php(96): Stripe\ApiRequestor->_requestRaw('post', '/v1/charges', Array, Array)
#4 /var/www/html/assets/vendor/stripe/lib/ApiOperations/Request.php(5 in /var/www/html/assets/vendor/stripe/lib/HttpClient/CurlClient.php on line 284
我最近使用一键 LAMP 部署在 Google Compute Engine 上创建了一个新虚拟机。我还使用 Lets Encrypt 来允许 https。此外,我已经下载了最新的 cacert.pem 文件并将其放在 /etc/ssl/certs
文件夹中。
证书文件夹具有以下权限:
drwxr-xr-x 2 root root 20480 Apr 5 14:31 certs
该文件具有以下权限:
-rw-r--r-- 1 root root 219596 Apr 5 14:29 cacert.pem
我还编辑了 php.ini
文件以将 curl.cainfo
和 openssl.cafile
指向 pem 文件并重新启动 Apache。
在查看 Stripe 的网站时,它提到现在需要 TLS 1.2。我已确认我的网站正在使用它。但是 Stripe 网站上的一些示例测试代码似乎表明它没有看到 TLS 1.2。
根据 ssllabs.com,我的站点被识别为具有 TLS 1.2 协议。
我添加到我的站点以验证的 Stripe 示例代码是:
\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
try {
\Stripe\Charge::all();
echo "TLS 1.2 supported, no action required.";
} catch (\Stripe\Error\ApiConnection $e) {
echo "TLS 1.2 is not supported. You will need to upgrade your integration.";
}
我还添加了以下内容以获取其他版本信息:
echo 'PHP version: ' . phpversion() . PHP_EOL . '<br/>';
echo 'cURL version: ' . curl_version()['version'] . PHP_EOL . '<br/>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.howsmyssl.com/a/check");
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo 'TLS version: ' . json_decode($response)->tls_version . PHP_EOL;
我运行时的结果是:
============= Stripe Suggested Test Code ============
TLS 1.2 is not supported. You will need to upgrade your integration.
================================================
==================== Version Code ===================
PHP version: 7.0.33-0+deb9u3
cURL version: 7.52.1
TLS version: TLS 1.2
================================================
在这一点上,我 运行 没有想法了。为了全面披露,我的大部分学习都是通过 Google 搜索和这个网站进行的,因此,如果您能在业余编码水平上提供任何帮助,我们将不胜感激。
所以,看着 the code 我看到了这个:
class CurlClient implements ClientInterface
{
public function request($method, $absUrl, $headers, $params, $hasFile)
{
...
$opts[CURLOPT_CAINFO] = Stripe::getCABundlePath();
...
}
}
这又将我引向 this code:
class Stripe
{
// @var string Path to the CA bundle used to verify SSL certificates
public static $caBundlePath = null;
/**
* @return string
*/
private static function getDefaultCABundlePath()
{
return realpath(dirname(__FILE__) . '/../data/ca-certificates.crt');
}
/**
* @return string
*/
public static function getCABundlePath()
{
return self::$caBundlePath ?: self::getDefaultCABundlePath();
}
/**
* @param string $caBundlePath
*/
public static function setCABundlePath($caBundlePath)
{
self::$caBundlePath = $caBundlePath;
}
}
这使得 Stripe 出于某种原因看起来不想使用系统 CA 路径。所以你可以:
- 使用
Stripe::setCABundlePath()
指向系统CA包
或
- 确保
data/ca-certificates.crt
的 CA 包(随 Stripe 一起提供)存在并且具有适当的权限。
我收到了这条错误消息。我通过重新安装 Stripe 库解决了这个问题。根本原因是 /data 目录丢失或损坏。