Perl LWP :: UserAgent,https到特定https网站的代理,未知协议错误

时间:2015-01-09 00:31:26

标签: perl proxy

阅读我能找到的有关主题的所有内容......无法确定如何使其成功。

我使用新更新的(2015年1月9日)Active State Perl和标准方法

my $ua=LWP::UserAgent->new();  
$ua->agent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/33.0');
$ua->timeout(120);
$ua->cookie_jar( {} );
$ua->proxy(['https'],'https://199.200.120.140:8089') #taken from http://proxylist.hidemyass.com/search-1308872#listable
my $response = $ua->get('https://www.comparis.ch');   #this web site I struggle with, I can connect to https://github.com for example... But I also can connect to comparis.ch through same proxy using urllib3 on Python3.4... 

如果有人可以解释如何从网站获得200?

的输出

响应返回Timeout(如果我使用http代理或

LWP::Protocol::https::Socket: SSL connect attempt failed error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol at E:/Perl64/lib/LWP/Protocol/http.pm line 49." 

如果我尝试

LWP::UserAgent->new(ssl_opts => { verify_hostname => 0, SSL_version => 'SSLv3' });

然后我

LWP::Protocol::https::Socket: SSL connect attempt failed error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number at E:/Perl64/lib/LWP/Protocol/http.pm line 49.

我认为该网站会在某些地区超时连接,因此必须使用来自美国或西欧的代理服务器。

根据要求我添加了调试输出(对于简单的UserAgent-> new() - 无选项),它从http://proxylist.hidemyass.com/search-1305502#listable尝试两个代理192.3.121.204:3128和64.31.22.131:7808。第一个似乎只是超时(很可能被阻止),但第二个表现出不同的行为。

perl -MIO::Socket::SSL=debug4 test.pl

DEBUG: .../IO/Socket/SSL.pm:2555: new ctx 61267216
DEBUG: .../IO/Socket/SSL.pm:539: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:1769: IO::Socket::INET configuration failed
DEBUG: .../IO/Socket/SSL.pm:2588: free ctx 61267216 open=61267216
DEBUG: .../IO/Socket/SSL.pm:2593: free ctx 61267216 callback
DEBUG: .../IO/Socket/SSL.pm:2600: OK free ctx 61267216
500 Can't connect to 192.3.121.204:3128 (10060)
Content-Type: text/plain
Client-Date: Fri, 09 Jan 2015 10:15:18 GMT
Client-Warning: Internal response

Can't connect to 192.3.121.204:3128 (10060)

LWP::Protocol::https::Socket: connect: 10060 at E:/Perl64/lib/LWP/Protocol/http.pm line 49.

DEBUG: .../IO/Socket/SSL.pm:2555: new ctx 61267216
DEBUG: .../IO/Socket/SSL.pm:539: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:541: socket connected
DEBUG: .../IO/Socket/SSL.pm:563: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:599: not using SNI because hostname is unknown
DEBUG: .../IO/Socket/SSL.pm:650: set socket to non-blocking to enforce timeout=120
DEBUG: .../IO/Socket/SSL.pm:663: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:673: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:683: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:703: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:663: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:1780: SSL connect attempt failed

DEBUG: .../IO/Socket/SSL.pm:1785: SSL connect attempt failed error:140770FC:SSL     routines:SSL23_GET_SERVER_HELLO:unknown protocol
DEBUG: .../IO/Socket/SSL.pm:669: fatal SSL error: SSL connect attempt failed error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
DEBUG: .../IO/Socket/SSL.pm:1769: IO::Socket::INET configuration failed
DEBUG: .../IO/Socket/SSL.pm:2588: free ctx 61267216 open=61267216
DEBUG: .../IO/Socket/SSL.pm:2593: free ctx 61267216 callback
DEBUG: .../IO/Socket/SSL.pm:2600: OK free ctx 61267216
500 Can't connect to 64.31.22.131:7808
Content-Type: text/plain
Client-Date: Fri, 09 Jan 2015 10:15:19 GMT
Client-Warning: Internal response

Can't connect to 64.31.22.131:7808

LWP::Protocol::https::Socket: SSL connect attempt failed error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol at E:/Perl64/lib/LWP/Protocol/http.pm line 49.

在Stefan建议之后我使用http://代理地址(而不是https),这产生了一些更好的结果如下,同样,它在Ubuntu下完全有效,但在Windows中却没有...

DEBUG: .../IO/Socket/SSL.pm:2555: new ctx 65664688
DEBUG: .../IO/Socket/SSL.pm:1354: start handshake
DEBUG: .../IO/Socket/SSL.pm:563: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:599: not using SNI because hostname is unknown
DEBUG: .../IO/Socket/SSL.pm:650: set socket to non-blocking to enforce timeout=120
DEBUG: .../IO/Socket/SSL.pm:663: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:673: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:683: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:703: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:663: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:673: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:683: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:703: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:663: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:673: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:683: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:703: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:663: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:673: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:683: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:703: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:2411: ok=1 cert=69181312
DEBUG: .../IO/Socket/SSL.pm:2411: ok=1 cert=69943488
DEBUG: .../IO/Socket/SSL.pm:2411: ok=1 cert=69943136
DEBUG: .../IO/Socket/SSL.pm:1559: scheme=www cert=69943136
DEBUG: .../IO/Socket/SSL.pm:1569: identity=www.comparis.ch cn=www.comparis.ch alt=2 www.comparis.ch 2 it.comparis.ch 2 en.comparis.ch 2 fr.comparis.ch
DEBUG: .../IO/Socket/SSL.pm:663: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:673: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:683: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:703: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:663: Net::SSLeay::connect -> 1
DEBUG: .../IO/Socket/SSL.pm:718: ssl handshake done
DEBUG: .../IO/Socket/SSL.pm:2588: free ctx 65664688 open=65664688
DEBUG: .../IO/Socket/SSL.pm:2593: free ctx 65664688 callback
DEBUG: .../IO/Socket/SSL.pm:2600: OK free ctx 65664688
500 Status read failed:A non-blocking socket operation could not be completed
immediately
Content-Type: text/plain
Client-Date: Fri, 09 Jan 2015 16:49:31 GMT
Client-Warning: Internal response

Status read failed: A non-blocking socket operation could not be completed immediately
at E:/Perl64/lib/Net/HTTP/Methods.pm line 276.

我想它现在有点不同了,但是我搜索了网页,却找不到任何答案。

2 个答案:

答案 0 :(得分:5)

我想我知道你的问题是什么。 当您执行https代理请求时,您没有使用HTTP协议连接到代理,而是使用HTTP协议,然后发出CONNECT请求来构建隧道。因此,代理的网址只能是http://,而不是https://

$ua->proxy(['https'],'http://199.200.120.140:8089');
                      ^^^^ http:// instead of https://

除此之外,请确保LWP :: UserAgent和LWP :: Protocol :: https至少是版本6.06,因为这些添加了对代理HTTPS流量的适当支持。但我认为这些版本在你的情况下应该是新的。

编辑:由于您在Windows上使用最新版本的IO :: Socket :: SSL运行代码,因此您触发了与Windows中新增添加的对非阻塞SSL套接字的支持相关的错误, "状态读取失败:无法立即完成非阻塞套接字操作"。有关详细信息和修复,请参阅https://github.com/libwww-perl/net-http/pull/11

答案 1 :(得分:1)

感谢Steffen,解决方案是https://github.com/libwww-perl/net-http/pull/11 我试过了,它在我的情况下正常工作。