【发布时间】:2017-09-15 12:22:17
【问题描述】:
我目前正在与 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
【问题讨论】:
-
你能把这个 Perl 脚本的开头添加到问题中吗?
-
请提供您声称已安装 LWP::Protocol::https 的依据。
-
你意识到程序在命令行上接受参数吗?如果请求中有错误,则响应不包含有效 JSON 的可能性不大。我建议您在传递给
decode_json之前打印$res的值。 -
您的脚本使用
/usr/bin/perl,但您可能使用/for/share/pkg/perl/5.10.1/bin/perl安装它。您需要切换您的脚本使用哪个perl,或者您需要使用/for/usr/bin/perl安装它。打电话,得走了。如果您还没有弄清楚,稍后会提供详细信息