我正在尝试将API用于Palo Alto Networks软件。该代码应该将用户网络登录的用户名和ipaddress提交到Web界面。
当我尝试使用PANs的API及其Windows机器的示例代码时,会抛出以下异常:
Can't use an undefined value as a symbol reference at
C:/Perl/lib/PAN/API.pm line 179 (#1)
PAN::API::UID::login('PAN::API::UID=HASH(0x7fd113828598)', 'SCU-DSM22/pmmertens', 172.16.6.117) called at API_events.pl line 12
这是API文档附带的代码示例:
#!/usr/bin/perl -w
use strict;
use PAN::API;
my $useridagent = '10.0.0.99'; #I changed this to our PAN server address
my $useridapi = PAN::API::UID->new($useridagent);
my $user = $ENV{USERDOMAIN}.'/'.$ENV{USERNAME};
my $ipaddress = unpack('W4',gethostbyname($ENV{COMPUTERNAME}));
$useridapi->login($user,$ipaddress);
我确保正确检索所有变量。替代字面值也没有帮助。谷歌搜索此错误出现了关于硬引用和软引用的引用,但我没有在下面的代码中看到这些规则的任何违规行为。
这是来自PAN / Api.pm的代码块。第179行是打印开始的地方。
sub submit () {
my $self = shift;
use IO::Socket::INET;
use IO::Socket::SSL;
my $socket = IO::Socket::INET->new(PeerAddr => $self->{server},
PeerPort => $self->{port},
Proto => 'tcp');
my $socketssl = IO::Socket::SSL->start_SSL( $socket,
SSL_version =>'TLSv1');
print $socketssl $self->xml;
$socketssl->close;
$socketssl->stop_SSL;
}
答案 0 :(得分:4)
IO :: Socket :: INET和IO :: Socket :: SSL行都应该进行错误检查。类似的东西:
my $socket = IO::Socket::INET->new(....)
or die "Failed to create socket: $!"
和
my $socketssl = IO::Socket::SSL->start_SSL(...)
or die "Failed to start SSL: ".IO::Socket::SSL::errstr();
虽然不是死,但我可能会选择Carp :: confess。