Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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:
$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;

In reply to Can't make WWW::Mechanize work through proxy programmatically by igoryonya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found