2016-08-29 218 views
0

我一直在試圖從這個腳本似乎無法從腳本

#!/usr/bin/env perl 
use strict; 
use warnings; 
use LWP::UserAgent; 
use File::Slurp::Tiny qw(write_file); 
use v5.16; 
my $dir = shift || "."; 
my $previo = shift || "IV-2015-16"; 
my $ua = LWP::UserAgent->new; 
$ua->agent("Mozilla/5.0"); 
for my $d (qw(ejercicios objetivos practicas sesiones)) { 
    my $url = "https://raw.githubusercontent.com/JJ/$previo/master/$d/README.md"; 
    my $response = $ua->get($url); 
    if ($response->is_success) { 
     my $file = $response->decoded_content; 
     say "$url gave $file"; 
     write_file($file, "$dir/$d/README.md") || die "Can't write file"; 
    } else { 
     die "Can't download this $url because ". $response->status_line; 
    } 
} 

網址是否正確自動下載一些內容GitHub的,但是它無法使用githubusercontent與

'_msg' => 'Can\'t connect to raw.githubusercontent.com:443' 
'_rc' => 500 

也就是說,返回500錯誤。

Can't download this https://raw.githubusercontent.com/JJ/IV-2015-16/master/ejercicios/README.md because 500 Can't connect to raw.githubusercontent.com:443 at /tmp/cosas.pl line 19. 

在/tmp/cosas.pl線19

我試圖設置用戶代理,它仍然無法正常工作。我想知道它是否需要身份驗證,但是使用wget或者將它放在URL欄上可以正確下載內容。任何想法?也許有些API禁止或限制?

+0

明顯的問題,但你從與互聯網連接的機器上運行呢? – simbabque

+0

如果我沒有......我不會有一個「500」錯誤我想我可以從本地代理得到404錯誤,但事實並非如此。它工作沒有使用wget的小故障,它只是客戶端不工作。 – jjmerelo

+0

你在代理/防火牆後面嗎?從這裏工作很好。 –

回答

0

這看起來像一個連接問題。您的瀏覽器可能使用代理。 wget也因爲環境變量設置正確:http_proxyHTTPS_PROXYALL_PROXY ...

但LWP :: UserAgent的不使用這些環境變量,除非明確地告知。加入這行只是用戶代理施工後:

$ua->env_proxy;