igoryonya has asked for the wisdom of the Perl Monks concerning the following question:
When I run the mechanize script from the shell with the /https?_proxy / set to the proxy server, it works through proxy, but when I run the script without that environment variable set in the shell and try to set the proxy internally in the program (script), it doesn't work.
I tried setting:
$ENV{'https_proxy'} = 'http://127.0.0.1:8118';
or:
$ENV{'HTTPS_PROXY'} = 'http://127.0.0.1:8118';
prior to calling:
$mech->get($url);
Also, I tried the same, as above, but adding the following prior to ->get command:
$mech->env_proxy;
Also, instead of setting the $ENV{var} with ->env_proxy command, the following, prior to ->get:
$mech->proxy(['https'], 'http://127.0.0.1:8118');
or:
$mech->proxy(['http'], 'http://127.0.0.1:8118');
Also, tried to disable https, as was suggested on some forums:
but nothing worked. My goal is to be able to dynamically switch proxy for the same url, i.e. different proxies are set to work through different providers and there is also an internet on direct connection. I want to cycle between direct connection and different proxies, on fail, until getting success. My current code is:
https://t.me/modernperl/217572
I tried setting:
$ENV{'https_proxy'} = 'http://127.0.0.1:8118';
or:
$ENV{'HTTPS_PROXY'} = 'http://127.0.0.1:8118';
prior to calling:
$mech->get($url);
Also, I tried the same, as above, but adding the following prior to ->get command:
$mech->env_proxy;
Also, instead of setting the $ENV{var} with ->env_proxy command, the following, prior to ->get:
$mech->proxy(['https'], 'http://127.0.0.1:8118');
or:
$mech->proxy(['http'], 'http://127.0.0.1:8118');
Also, tried to disable https, as was suggested on some forums:
$mech->proxy(['http'], 'http://127.0.0.1:8118'); $mech->proxy(['https'], undef);
but nothing worked. My goal is to be able to dynamically switch proxy for the same url, i.e. different proxies are set to work through different providers and there is also an internet on direct connection. I want to cycle between direct connection and different proxies, on fail, until getting success. My current code is:
#!/usr/bin/env perl use WWW::Mechanize; my @https_proxy = ( 'http://127.0.0.1:8118' ); my $url = shift; #print "LWP::Protocol::https::VERSION: ($LWP::Protocol::https::VERSION +)\n"; $ENV{'https_proxy'} = $https_proxy[0]; my $mech = WWW::Mechanize->new(autocheck=>1); $mech->proxy(['http'], $https_proxy[0]); #$mech->proxy(['https'], undef); #$mech->env_proxy; $mech->get($url); print $mech->content;
UPDATE
So, since I got no help here, I got help from people on perl telegram channel:https://t.me/modernperl/217572
$ENV{'HTTPS_PROXY'} = 'http://127.0.0.1:8118'; my $mech = WWW::Mechanize->new( autocheck=>1, noproxy=>0 ); $mech->env_proxy;
|
---|
Back to
Seekers of Perl Wisdom