我目前正在与 USGS 的 EarthExplorer 合作,根据空间坐标设置一些 Landsat 场景的批量下载。他们在https://earthexplorer.usgs.gov/inventory/example/json-download_data-pl提供了一个很棒的方便的脚本来执行此操作,这很棒。我正在处理集群,尽管正确安装了所有 perl 模块,但当我运行脚本时,我得到以下输出:
Running Script...
Error: Error: malformed JSON string, neither array, object, number, string or
atom, at character offset 0 (before "LWP will support htt...") at ./dl.pl line 182
这似乎很好奇。作为解释,脚本以
#!/usr/bin/perl
#use strict;
use warnings;
use 5.010;
use JSON;
use Scalar::Util qw(looks_like_number reftype dualvar );
use LWP::UserAgent;
use Getopt::Long qw(GetOptions);
my ($username, $password);
$username = "myusername_filled_in";
$password = "mypassword_filled_in";
GetOptions(
'username=s' => \$username,
'password=s' => \$password,
) or die "Error retrieving Username and Password\n";
有问题的代码是
$res = $response->{_content};
$res = decode_json $res;
根据Can't run Perl script on other computer中非常有用的建议,我完成了以下操作:
更改
$response->content
为$response->decoded_content( charset => 'none')
代码的违规区域。Ran
lwp-request https://google.com/
刚刚拉回了一个完整的网页 - 没有错误。所以,这似乎奏效了。试图通过插入来查看一些调试
print $response->decoded_content( charset => 'none');
,然后抛出错误
LWP will support https URLs if the LWP::Protocol::https module is installed.
而且,确实安装了 LWP::Protocol::https。
我觉得我必须缺少一些简单的东西——比如我如何定义我的用户名和密码($username = "myusername";
等等,在声明变量之后)或其他一些愚蠢的东西。
有没有其他人遇到过这个?
要添加以下查询的输出:
$ which cpan ; head -n 1 `which cpan` ; echo 'o conf' | cpan | grep -P 'make|mbuild' ; set | grep ^PERL ; which perl ; perl -le'use LWP::Protocol::https; print "ok";'
/share/pkg/perl/5.10.1/bin/cpan
#!/share/pkg/perl/5.10.1/bin/perl
make [/usr/bin/make]
make_arg []
make_install_arg []
make_install_make_command [/usr/bin/make]
makepl_arg []
mbuild_arg []
mbuild_install_arg []
mbuild_install_build_command [./Build]
mbuildpl_arg []
PERL5LIB=/home/jb92b/perl5/lib/perl5:/home/jb92b/perl5/lib/perl5:/home/jb92b/perl5/lib/perl5
PERL_LOCAL_LIB_ROOT=/home/jb92b/perl5:/home/jb92b/perl5:/home/jb92b/perl5
PERL_MB_OPT='--install_base "/home/jb92b/perl5"'
PERL_MM_OPT=INSTALL_BASE=/home/jb92b/perl5
/share/pkg/perl/5.10.1/bin/perl
ok