当使用perl和earthexplorer时格式错误的JSON字符串
我目前正在与USGS的EarthExplorer一起根据空间坐标设置一些Landsat场景的批量下载。他们提供了一个非常好用的脚本,在https://earthexplorer.usgs.gov/inventory/example/json-download_data-pl这很好。我工作的集群上,尽管在正确安装的所有Perl模块,当我运行该脚本,我得到以下的输出:当使用perl和earthexplorer时格式错误的JSON字符串
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 ::协议:: HTTPS安装。
我觉得我必须有一些简单的东西,我很想念 - 就像我如何定义我的用户名和密码(只是$username = "myusername";
等,声明变量后)或其他asinine。
有没有其他人遇到过这个问题?
从下面的查询添加输出:
$ 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
您的代码不检查错误。你应该有类似的东西
$response->is_success()
or die("Can't fetch X: ".$response->status_line());
你遇到的问题是LWP :: Protocol :: https没有安装。
你声称是这样的,但Perl在这里是权威的:)它不是由那个Perl安装的,你将它安装在一个非标准的目录中,而不告诉Perl在那里寻找它,或者有权限问题。
在这种情况下,您的脚本使用/usr/bin/perl
,但是您使用/ for /share/pkg/perl/5.10.1/bin/perl
安装了该模块。您需要切换脚本使用哪个perl
,或者您需要使用/ for /usr/bin/perl
安装模块。 “
”类似于我如何定义我的用户名和密码(只是$username = "myusername";
等,该变量的声明后)”
你不应该修改代码来添加用户名和密码。它的编写方式,调用GetOptions
将覆盖它们。你应该使用
program.pl --usernam myusername --password mypassword
灿您将此Perl脚本的开头添加到该问题中? – raina77ow
根据请求编辑。另请参阅https://earthexplorer.usgs.gov/inventory/example/json-download_data-pl – jebyrnes
请提供您的声明的基础:LWP: :Protocol :: https已安装 – ikegami