使用 Vimeo api 在获取视频列表时会出现间歇性 ssl 错误
Using the Vimeo api gives intermittent ssl error when getting video list
我在使用 PHP API here 时遇到问题。它有效,但每第二次或第三次请求我都会收到以下错误:
Unable to complete request.[SSL connect error]
这发生在 Vimeo.php:154。这是在 curl 执行之后。我尝试在命令行中单独使用 curl 并得到:
curl: (35) SSL connect error
本文引用:
A problem occurred somewhere in the SSL/TLS handshake. You really want the error buffer and read the message there as it pinpoints the problem slightly more. Could be certificates (file formats, paths, permissions), passwords, and others.
所以我用 PHP file_get_contents 试了一下,我得到的警告是
Warning: file_get_contents(): SSL: Connection reset by peer
我有点不知道这是从哪里来的,不知道这是 VImeo 有时拒绝我的请求还是服务器有时失去连接。我想知道是否有人以前遇到过这个问题,或者我可以采取一些步骤来获得更多关于导致问题的线索。这是我的代码
使用file_Gets_contents
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Authorization: bearer <Personal access token>\r\n"
),
'ssl'=>array(
'allow_self_signed'=>false,
'verify_peer'=>false,
)
);
$context = stream_context_create($opts);
$userAccount = '<user account>';
$url = "https://api.vimeo.com/users/$userAccount/videos";
$unparsed_json = file_get_contents($url, false, $context);
$json_object = json_decode($unparsed_json);
var_dump($json_object);die();
使用 CURL
$userAccount = '<user account>';
$url = "https://api.vimeo.com/users/$userAccount/videos";
$curlHeader = [
'Authorization: bearer <Personal access token>',
'Accept: ' . self::VERSION_STRING,
];
$ch = curl_init();
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeader);
curl_setopt($ch, CURLOPT_HTTPGET, true);
$unparsed_json = curl_exec ($ch);
// Check if any error occurred
if(curl_errno($ch))
{
$info = curl_getinfo($ch);
var_dump('Curl error: ', curl_error($ch), ' Curl error no: ', curl_errno($ch), ' Unparsed json: ', $unparsed_json, ' Info: ', $info, 'DIR CERT: ', __DIR__ . '/CERT'); die();
}
curl_close ($ch);
$json_object = json_decode($unparsed_json);
var_dump($unparsed_json);die();
使用Vimeo.php
$userAccount = '<user account>';
$url = "https://api.vimeo.com/users/$userAccount/videos";
$client_id = '<Client ID>';
$client_secret = '<Secret>';
$lib = new Vimeo\Vimeo($client_id, $client_secret);
$lib->setToken('<Personal access token>');
$response = $lib->request($url, [], 'GET');
var_dump($response['body']);die();
我在 Linux 命令行的 curl 上使用了 verbose 并看到了这个:
About to connect() to api.vimeo.com port 443 (#0)
Trying 104.156.85.217... connected
Connected to api.vimeo.com (104.156.85.217) port 443 (#0)
Initializing NSS with certpath: sql:/etc/pki/nssdb
CAfile: 'cert file location'
CApath: none
NSS error -5961
Closing connection #0
SSL connect error
curl: (35) SSL connect error
我发现问题是 Web 过滤器被阻止了。我发现的方法是直接使用 openssl:
[username@server username]$ openssl s_client -connect :443 -msg
CONNECTED(00000003)
'>>> TLS 1.2 Handshake [length 00f4], ClientHello
write:errno=104
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 249 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
---
我在使用 PHP API here 时遇到问题。它有效,但每第二次或第三次请求我都会收到以下错误:
Unable to complete request.[SSL connect error]
这发生在 Vimeo.php:154。这是在 curl 执行之后。我尝试在命令行中单独使用 curl 并得到:
curl: (35) SSL connect error
本文引用:
A problem occurred somewhere in the SSL/TLS handshake. You really want the error buffer and read the message there as it pinpoints the problem slightly more. Could be certificates (file formats, paths, permissions), passwords, and others.
所以我用 PHP file_get_contents 试了一下,我得到的警告是
Warning: file_get_contents(): SSL: Connection reset by peer
我有点不知道这是从哪里来的,不知道这是 VImeo 有时拒绝我的请求还是服务器有时失去连接。我想知道是否有人以前遇到过这个问题,或者我可以采取一些步骤来获得更多关于导致问题的线索。这是我的代码
使用file_Gets_contents
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Authorization: bearer <Personal access token>\r\n"
),
'ssl'=>array(
'allow_self_signed'=>false,
'verify_peer'=>false,
)
);
$context = stream_context_create($opts);
$userAccount = '<user account>';
$url = "https://api.vimeo.com/users/$userAccount/videos";
$unparsed_json = file_get_contents($url, false, $context);
$json_object = json_decode($unparsed_json);
var_dump($json_object);die();
使用 CURL
$userAccount = '<user account>';
$url = "https://api.vimeo.com/users/$userAccount/videos";
$curlHeader = [
'Authorization: bearer <Personal access token>',
'Accept: ' . self::VERSION_STRING,
];
$ch = curl_init();
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeader);
curl_setopt($ch, CURLOPT_HTTPGET, true);
$unparsed_json = curl_exec ($ch);
// Check if any error occurred
if(curl_errno($ch))
{
$info = curl_getinfo($ch);
var_dump('Curl error: ', curl_error($ch), ' Curl error no: ', curl_errno($ch), ' Unparsed json: ', $unparsed_json, ' Info: ', $info, 'DIR CERT: ', __DIR__ . '/CERT'); die();
}
curl_close ($ch);
$json_object = json_decode($unparsed_json);
var_dump($unparsed_json);die();
使用Vimeo.php
$userAccount = '<user account>';
$url = "https://api.vimeo.com/users/$userAccount/videos";
$client_id = '<Client ID>';
$client_secret = '<Secret>';
$lib = new Vimeo\Vimeo($client_id, $client_secret);
$lib->setToken('<Personal access token>');
$response = $lib->request($url, [], 'GET');
var_dump($response['body']);die();
我在 Linux 命令行的 curl 上使用了 verbose 并看到了这个:
About to connect() to api.vimeo.com port 443 (#0)
Trying 104.156.85.217... connected
Connected to api.vimeo.com (104.156.85.217) port 443 (#0)
Initializing NSS with certpath: sql:/etc/pki/nssdb
CAfile: 'cert file location'
CApath: none
NSS error -5961
Closing connection #0
SSL connect error
curl: (35) SSL connect error
我发现问题是 Web 过滤器被阻止了。我发现的方法是直接使用 openssl:
[username@server username]$ openssl s_client -connect :443 -msg
CONNECTED(00000003)
'>>> TLS 1.2 Handshake [length 00f4], ClientHello
write:errno=104
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 249 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
---