Very Frustrating

Discussion in 'Perl Misc' started by schnibitz, Jul 30, 2009.

  1. schnibitz

    schnibitz Guest

    Hi everyone, the following code works from my linux shell as root or
    the 'nobody' accounts:
    -----------------------------

    #!/usr/bin/perl
    #use strict;
    #use LWP::Simple;
    use LWP::UserAgent;
    #use URI::URL;

    print "Content-type: text/html\n\n";
    print <<HTML;
    <html>
    <head>
    <title>TEST</title>
    </head>
    <body>
    HTML

    my $url_variable = $input{'URL'};

    my $ua = new LWP::UserAgent;
    $ua->timeout(120);
    my $request = new HTTP::Request('GET', 'http://www.yahoo.com');
    my $response = $ua->request($request);
    my $content = $response->content();
    print "$content";
    print <<HTML;
    </body>
    </html>
    </head>
    HTML
    ---------------------------------

    BUT when I hit that same .pl file with my browser I get the following
    error:

    500 Can't connect to www.yahoo.com:80 (Bad hostname 'www.yahoo.com')

    Can someone help me please? I'm doing something idiotic, I know, and
    anything you could do to help would be appreciated.

    -G
     
    schnibitz, Jul 30, 2009
    #1
    1. Advertising

  2. schnibitz

    schnibitz Guest

    On 29 July, 18:48, Tad J McClellan <> wrote:
    > schnibitz <> wrote:
    > > #use strict;

    >
    > You lose all of the benfits of that pragma when you comment
    > it out like that.
    >
    > --
    > Tad McClellan
    > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


    Thank you, I've tried both ways BTW, and it doesn't give me any more
    helpful messages. I checked DNS on my server. I can ping the
    address, and it resolves to an IP just fine. I've checked the perl
    resolver by issuing a special perl command, and it too resolves just
    fine. I can wget the site without issue, my /etc/hosts file has two
    measly entries, so I don't think that a corrupt hosts file has
    anything to do with it. Why would it work command-line, but not when
    invoked through the browser?
     
    schnibitz, Jul 30, 2009
    #2
    1. Advertising

  3. schnibitz

    schnibitz Guest

    On 29 July, 19:59, Tony Curtis <> wrote:
    > > Thank you, I've tried both ways BTW, and it doesn't give me any more
    > > helpful messages.  I checked DNS on my server.  I can ping the
    > > address, and it resolves to an IP just fine.  I've checked the perl
    > > resolver by issuing a special perl command, and it too resolves just
    > > fine.  I can wget the site without issue, my /etc/hosts file has two
    > > measly entries, so I don't think that a corrupt hosts file has
    > > anything to do with it.  Why would it work command-line, but not when
    > > invoked through the browser?

    >
    > maybe there's something restricted about the web server?
    >
    > if it works from the command-line then there's nothing
    > obviously wrong with the perl logic: maybe there's
    > something to do with the web server config that breaks
    > things?
    >
    > hth
    > t


    Hi there, great suggestion, and I'll be doing that from now on. I
    added all of that in, and I'm still not getting any helpful errors. I
    don't understand why it works in the shell, but not when invoked from
    a browser. I know that the browser hits that file from a different
    user (nobody I think) and I've tried invoking it from the "nobody"
    acct BTW.

    Here is the updated code with your suggested additions, and minor
    clarifications:

    _______________________________________
    #!/usr/bin/perl
    use strict;
    use warnings;
    use diagnostics;
    #use LWP::Simple;
    use LWP::UserAgent;
    #use URI::URL;

    my $content = 0;
    my $error = 0;

    print "Content-type: text/html\n\n";
    print <<HTML;
    <html>
    <head>
    <title>TEST</title>
    </head>
    <body>
    HTML
    &getpage;
    print "$content";
    print "$error";
    print <<HTML;
    </body>
    </html>
    </head>
    HTML

    sub getpage {
    my $ua = new LWP::UserAgent;
    $ua->timeout(120);
    my $request = new HTTP::Request('GET', 'http://www.yahoo.com');
    my $response = $ua->request($request);
    if ($response->is_success) {
    $content = $response->content;
    }
    else {
    $error = $response->status_line, "\n";
    }
    }

    _____________________________________
    Any other things I can try?
     
    schnibitz, Jul 30, 2009
    #3
  4. schnibitz

    schnibitz Guest

    On 29 July, 19:59, Tony Curtis <> wrote:
    > > Thank you, I've tried both ways BTW, and it doesn't give me any more
    > > helpful messages.  I checked DNS on my server.  I can ping the
    > > address, and it resolves to an IP just fine.  I've checked the perl
    > > resolver by issuing a special perl command, and it too resolves just
    > > fine.  I can wget the site without issue, my /etc/hosts file has two
    > > measly entries, so I don't think that a corrupt hosts file has
    > > anything to do with it.  Why would it work command-line, but not when
    > > invoked through the browser?

    >
    > maybe there's something restricted about the web server?
    >
    > if it works from the command-line then there's nothing
    > obviously wrong with the perl logic: maybe there's
    > something to do with the web server config that breaks
    > things?
    >
    > hth
    > t


    Hadn't thought of that, I'll check into that possibility. Thank you!
     
    schnibitz, Jul 30, 2009
    #4
  5. schnibitz

    schnibitz Guest

    On 29 July, 21:13, Tad J McClellan <> wrote:
    > schnibitz <> wrote:
    > > I
    > > don't understand why it works in the shell, but not when invoked from
    > > a browser.  I know that the browser hits that file from a different
    > > user (nobody I think) and I've tried invoking it from the "nobody"
    > > acct BTW.

    >
    > If you "think" wrong, then the fact that it runs as nobody is irrelevant.
    >
    > What is relevant is if it runs from the command line as the same use
    > that your CGI program runs as.
    >
    > So the first step is to determine what user your CGI programs run as.
    >
    >     #!/usr/bin/perl
    >     print "Content-Type: text/plain\n\n";
    >     system 'whoami';
    >
    > > print "$content";

    >
    >     perldoc -q vars
    >
    > --
    > Tad McClellan
    > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


    Hi Tad, fair enough, I removed the quotes. I normally don't use them,
    but I started just trying anything (yeah I'm that desperate). Anyway,
    I added the "system 'whoami';" command, and it shows "apache" instead
    of "nobody". So I su to "apache" and ran the script again.
    Flawless. Not a single error or anything thrown that I can see.
    Still getting "bad hostname" error when accessed from the browser.
     
    schnibitz, Jul 30, 2009
    #5
  6. schnibitz

    schnibitz Guest

    On 29 July, 22:01, schnibitz <> wrote:
    > On 29 July, 21:13, Tad J McClellan <> wrote:
    >
    >
    >
    > > schnibitz <> wrote:
    > > > I
    > > > don't understand why it works in the shell, but not when invoked from
    > > > a browser.  I know that the browser hits that file from a different
    > > > user (nobody I think) and I've tried invoking it from the "nobody"
    > > > acct BTW.

    >
    > > If you "think" wrong, then the fact that it runs as nobody is irrelevant.

    >
    > > What is relevant is if it runs from the command line as the same use
    > > that your CGI program runs as.

    >
    > > So the first step is to determine what user your CGI programs run as.

    >
    > >     #!/usr/bin/perl
    > >     print "Content-Type: text/plain\n\n";
    > >     system 'whoami';

    >
    > > > print "$content";

    >
    > >     perldoc -q vars

    >
    > > --
    > > Tad McClellan
    > > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

    >
    > Hi Tad, fair enough, I removed the quotes.  I normally don't use them,
    > but I started just trying anything (yeah I'm that desperate).  Anyway,
    > I added the "system 'whoami';" command, and it shows "apache" instead
    > of "nobody".  So I su to "apache" and ran the script again.
    > Flawless.  Not a single error or anything thrown that I can see.
    > Still getting "bad hostname" error when accessed from the browser.


    Okay, one other quick thing . . . So when I add the IP for www.yahoo.com
    into the /etc/hosts file, here's what I get when I run it from my
    browser now:

    0500 Can't connect to www.yahoo.com:80 (Permission denied)

    Different message. Anyone make anything of that?
     
    schnibitz, Jul 30, 2009
    #6
  7. schnibitz

    schnibitz Guest

    On 29 July, 22:01, schnibitz <> wrote:
    > On 29 July, 21:13, Tad J McClellan <> wrote:
    >
    >
    >
    > > schnibitz <> wrote:
    > > > I
    > > > don't understand why it works in the shell, but not when invoked from
    > > > a browser.  I know that the browser hits that file from a different
    > > > user (nobody I think) and I've tried invoking it from the "nobody"
    > > > acct BTW.

    >
    > > If you "think" wrong, then the fact that it runs as nobody is irrelevant.

    >
    > > What is relevant is if it runs from the command line as the same use
    > > that your CGI program runs as.

    >
    > > So the first step is to determine what user your CGI programs run as.

    >
    > >     #!/usr/bin/perl
    > >     print "Content-Type: text/plain\n\n";
    > >     system 'whoami';

    >
    > > > print "$content";

    >
    > >     perldoc -q vars

    >
    > > --
    > > Tad McClellan
    > > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

    >
    > Hi Tad, fair enough, I removed the quotes.  I normally don't use them,
    > but I started just trying anything (yeah I'm that desperate).  Anyway,
    > I added the "system 'whoami';" command, and it shows "apache" instead
    > of "nobody".  So I su to "apache" and ran the script again.
    > Flawless.  Not a single error or anything thrown that I can see.
    > Still getting "bad hostname" error when accessed from the browser.


    Okay, last post I swear. That last error got me to realize that
    selinux was hurting me. It would not allow my script to open up a
    port. Thank you to everyone for bearing with me, and hopefully this
    will help some poor soul out there.
     
    schnibitz, Jul 30, 2009
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rtmc
    Replies:
    7
    Views:
    413
  2. David Cho
    Replies:
    3
    Views:
    1,429
    Steve C. Orr [MVP, MCSD]
    Apr 7, 2005
  3. Raymond Arthur St. Marie II of III

    very Very VERY dumb Question About The new Set( ) 's

    Raymond Arthur St. Marie II of III, Jul 23, 2003, in forum: Python
    Replies:
    4
    Views:
    499
    Raymond Hettinger
    Jul 27, 2003
  4. shanx__=|;-

    very very very long integer

    shanx__=|;-, Oct 16, 2004, in forum: C Programming
    Replies:
    19
    Views:
    1,675
    Merrill & Michele
    Oct 19, 2004
  5. Abhishek Jha

    very very very long integer

    Abhishek Jha, Oct 16, 2004, in forum: C Programming
    Replies:
    4
    Views:
    444
    jacob navia
    Oct 17, 2004
Loading...

Share This Page