Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Can't call method... works locally, but not on webserver.

by lwicks (Friar)
on Nov 08, 2006 at 11:59 UTC ( [id://582860]=perlquestion: print w/replies, xml ) Need Help??

lwicks has asked for the wisdom of the Perl Monks concerning the following question:

Wise monks, please help this lowly Perl hacker with an annoying problem. I am working on a email script and ran into problems. I have hacked together the following script to test if I can access a pop3 server. When run locally on my M$ XP box under cygwin it works fine, when I upload it to my hosted webserver it fails and it is beyond me as to why. The error I get is: Can't call method "login" on an undefined value at /home/xxx/xxx/TestPopMail.pl line 22. Any suggestions, the small script is listed below.
#!/usr/bin/perl -wT use CGI::Carp qw( fatalsToBrowser ); print "Content-type: text/html\n\n"; print "<html><head><title>Test Page</title></head><body>"; $| = 1; use warnings; use strict; eval( "use Net::POP3;" ); die "Module Configuration Error: $@" if $@; my $time = scalar localtime; my $pop3 = "xxx.xxx.xxx"; my $login = "xxx\@xxx.xxx"; my $pass = "xxxxxxxx"; my $pop = Net::POP3->new($pop3); #my $smtp = Net::SMTP->new($ssmtp); $res = $pop->login($login, $pass); if ($res eq "undef"){ print "Couldn't connect $!\n"; } else { print "On $time e-mail status inbox: $res post \n"; } my $i =0; print("Deleting $res mails ...\n"); for($i = 0; $i<$res; $i++) { # $pop->delete($i); } $pop->quit(); print "</html></body>";
_update/idea_ Looking at this I am wondering if I am not getting a connection to the pop3 server, and that in turn is causing the error in the login call?

Kia Kaha, Kia Toa, Kia Manawanui!
Be Strong, Be Brave, Be perservering!

Replies are listed 'Best First'.
Re: Can't call method... works locally, but not on webserver.
by davorg (Chancellor) on Nov 08, 2006 at 12:10 UTC

    You aren't checking the return value from Net::POP3->new - and that call seems to be failing. Perhaps your web server can't access the POP3 server that you're trying to connect to.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Aha... following your suggestion I changed the line to:
      my $pop = Net::POP3->new($pop3) or die "Unable to connect: $!";
      Which returned: Unable to connect: Connection timed out at /home/xxx/xxx/DeletePopMail.pl line 19 Now all I have to do is work out why I can connect from my PC but not via the webserver! Thanks for the useful reply, much appreciated.
        I ran into a similar problem (CGI script unable to access the network) and discovered that it stemmed in my case from SELinux, the NSA's secured Linux kernel. It is built into Fedora from core 3 onwards, as well as some other distros, and is installed on many individual servers besides. If you determine that you are running selinux (try the command /usr/sbin/selinuxenabled (default path). If it returns 0, you have it), it has a variable called httpd_can_network_connect. Set this to 1 and selinux will stop blocking CGI network connections.
Re: Can't call method... works locally, but not on webserver.
by codeacrobat (Chaplain) on Nov 08, 2006 at 22:36 UTC
    It is generally better to check
    if (! defined $res )
    instead of
    if ($res eq "undef")
    if Net::POP3->new fails with an undef value.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://582860]
Approved by Corion
Front-paged by derby
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found