2017-09-13 68 views
0

我目前正在與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繼非常有用的意見,我也做了以下內容:

  1. 在違規代碼區域更改了$response->content$response->decoded_content(charset => 'none')

  2. ran lwp-request https://google.com/剛剛拉回完整的網頁 - 沒有錯誤。所以,這似乎工作。

  3. 試圖通過插入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 
+0

燦您將此Perl腳本的開頭添加到該問題中? – raina77ow

+0

根據請求編輯。另請參閱https://earthexplorer.usgs.gov/inventory/example/json-download_data-pl – jebyrnes

+1

請提供您的聲明的基礎:LWP: :Protocol :: https已安裝 – ikegami

回答

1

您的代碼不檢查錯誤。你應該有類似的東西

$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安裝模塊。 「

+0

'數據庫生成於2017年9月13日星期三15:29:02 GMT LWP :: Protocol :: https是最新的(6.07)。 ' – jebyrnes

+0

呵呵 - 然後用你的調試代碼:'錯誤:無法獲取X:501協議方案'https'不受支持(LWP :: Protocol :: https未安裝)' – jebyrnes

+0

那麼,就像我說的那樣:它不是由那個Perl安裝的,你安裝它是一個非標準的目錄而不告訴Perl在那裏尋找它,或者有一個權限問題。 – ikegami

0

」類似於我如何定義我的用戶名和密碼(只是$username = "myusername";等,該變量的聲明後)」

你不應該修改代碼來添加用戶名和密碼。它的編寫方式,調用GetOptions將覆蓋它們。你應該使用

program.pl --usernam myusername --password mypassword