【问题标题】:Perl LWP::Simple "Name or Service Not Known" errorPerl LWP::简单的“名称或服务未知”错误
【发布时间】:2020-02-02 20:47:22
【问题描述】:

在过去一周的某个时候,我开始收到使用 URL 并检索内容的代码的错误。

这使用 Perl 模块 LWP::Simple

模块或我们的代码没有任何更改。服务器主机说没有任何变化。

http 或 https 会发生这种情况

它发生在我们托管的域之外。

来自其他服务器的 URL 不会发生这种情况。

这是错误

Result: $VAR1 = bless( { '_content' => 'Can\'t connect to coloradosportscards.ultimatecardstore.com:443 (Name or service not known) Name or service not known at /usr/local/share/perl5/LWP/Protocol/http.pm line 52. ',
'_rc' => 500,
 '_headers' => bless( { 'client-warning' => 'Internal response', 'client-date' => 'Sun, 02 Feb 2020 19:40:24 GMT',
 'content-type' => 'text/plain',
 '::std_case' => { 'client-warning' => 'Client-Warning', 'client-date' => 'Client-Date' } }, 'HTTP::Headers' ),
 '_msg' => 'Can\'t connect to coloradosportscards.ultimatecardstore.com:443 (Name or service not known)', '_request' => bless( { '_content' => '',
 '_uri' => bless( do{\(my $o = 'https://coloradosportscards.ultimatecardstore.com/online_store/store/images/0000697417.jpg')},
 'URI::https' ),
 '_headers' => bless( { 'user-agent' => 'Mozilla/5.0' },
 'HTTP::Headers' ), '_method' => 'GET' },
 'HTTP::Request' ) },
 'HTTP::Response' ); 

我们正在尝试访问此图像,它存在

https://coloradosportscards.ultimatecardstore.com/online_store/store/images/0000697417.jpg

提前感谢您的关注

迈克

【问题讨论】:

  • 你安装了 LWP::Protocol::https 吗?
  • 是的,LWP::Protocol::Https 6.07版这段代码已经工作多年了
  • 似乎是 DNS 或 /etc/hosts 中的问题。
  • 由于错误 500 是一般的服务器错误,我怀疑问题出在这一端,而不是代码或运行代码的环境。我知道你说他们说没有任何改变,但这可能是升级或改变他们没有意识到导致问题的任何数量的事情。您可以使用 curl 或其他方式从服务器上拉下图像以确认它可以访问吗?
  • perl -MLWP::Simple -e "getprint('coloradosportscards.ultimatecardstore.com/online_store/store/…)" 对我来说很好用。您能否分享代码或提供重现问题的最小示例?

标签: perl lwp


【解决方案1】:

以下代码检索图像没有任何问题

use strict;
use warnings;
use feature 'say';

use LWP::Simple;

my $base = 'https://coloradosportscards.ultimatecardstore.com';
my $url  = $base . '/online_store/store/images/0000697417.jpg';
my $file = $1 if $url =~ m|/(\d+\.jpg)|;

if (is_success(getstore($url, $file))) {
    say "Retrieved $file successfully";
} else {
    say "Couldn't retrieve $file";
}

【讨论】:

    【解决方案2】:

    我的服务器人员解决了它。不太确定他们做了什么,但确实有效。

    Cpanel 更新是否会改变环境。这确实突然开始发生,我的代码没有更改。

    是的,cPanel 也有机会升级服务器托管环境所需的合适软件包,但他们只会在经过大量测试后才会这样做。 由于提到的错误还指向“名称或服务未知”,因此有可能无法从服务器内部正确进行解析。我们现在稍微向服务器添加了另一个解析器 IP。请检查并看看你的结果如何。

    【讨论】:

    • 也许 SElinux 或类似的东西阻止了它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-18
    • 1970-01-01
    • 1970-01-01
    • 2018-06-02
    • 2019-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多