【问题标题】:Using the Vimeo api gives intermittent ssl error when getting video list获取视频列表时使用 Vimeo api 会出现间歇性 ssl 错误
【发布时间】:2016-03-22 21:31:36
【问题描述】:

我在使用 PHP API here 时遇到问题。它可以工作,但每第二次或第三次请求我都会收到以下错误:

无法完成请求。[SSL 连接错误]

这发生在 Vimeo.php:154 上。这是在 curl 执行之后。我尝试在命令行中单独使用 curl 并得到:

curl: (35) SSL 连接错误

此引用:

SSL/TLS 握手中出现问题。您真的需要错误缓冲区并在那里阅读消息,因为它可以稍微定位问题。可以是证书(文件格式、路径、权限)、密码等。

所以我用 PHP file_get_contents 尝试了它,我得到的警告是

警告: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 并看到了这个:

关于 connect() 到 api.vimeo.com 端口 443 (#0)
正在尝试 104.156.85.217... 已连接
连接到 api.vimeo.com (104.156.85.217) 端口 443 (#0)
使用 certpath 初始化 NSS:sql:/etc/pki/nssdb
CAfile: '证书文件位置'
CApath:无
NSS 错误 -5961
关闭连接 #0
SSL 连接错误

curl: (35) SSL 连接错误

【问题讨论】:

    标签: php curl https rhel vimeo-api


    【解决方案1】:

    我发现问题在于网络过滤器被阻止。我发现的方法是直接使用openssl:

    [用户名@服务器用户名]$ openssl s_client -connect :443 -msg
    已连接(00000003)
    '>>> TLS 1.2 握手 [长度 00f4],ClientHello
    write:errno=104
    ---
    没有可用的对等证书
    ---
    未发送客户端证书 CA 名称
    ---
    SSL 握手已读取 0 个字节并写入 249 个字节
    ---
    新,(NONE),密码是 (NONE)
    不支持安全重新协商
    压缩:无
    扩展:无
    ---

    【讨论】:

    • 您说的是哪个网络过滤器?一个在 vimeo 上,还是在您的网络上?我遇到了同样的间歇性错误。
    • 这是我们端网络上的一个网络过滤器,它被阻止了。
    • 我们如何解决这个问题??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    • 2018-05-23
    • 2015-04-02
    • 1970-01-01
    相关资源
    最近更新 更多