Hi

I receive error when calling GitHub API from Perl (LWP). Basically, the
problemis authentication failure, although the username and password
combination is valid.

In the code snippet below, I have tried changing the values passed to
credentials() in several ways, however it does not work.

#!/usr/bin/perl

use warnings;
use strict;

use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request::Common qw(GET);

my $url = shift;
chomp $url;
my $auth_token = "username:token"

#my ($login, $pass) = split /:/, $auth_token;
#print "\nDEBUG: $login\n\n";

my $ua = LWP::UserAgent->new;
$ua->agent('Mozilla/8.0');

#$ua->credentials("www.github.com:443","Authorization: token", "$login",
"$pass");
$ua->credentials("api.github.com:443","Authorization
Basic:","$auth_token","");

my $request = GET "$url";
my $resp = $ua->request($request);

my $httpd_code = $resp->status_line;
my $code_cont = $resp->decoded_content;

if ($httpd_code eq "200 OK"){
    print "$code_cont\n";;
}
else {
        print "ERROR: $httpd_code $code_cont\n";
}


Receive 404 code: in GitHub API terms, this means authentication failed.

$ lwpagent.pl  https://api.github.com/teams/123456
'https://api.github.com/teams/123456'
404 Not Found {"message":"Not Found","documentation_url":"
https://developer.github.com/v3"}

GitHub API will return 404 Not Found, instead of 403 Forbidden, in some
places. This is to prevent the accidental leakage of private repositories
to unauthorized users.

if I remove the credentials() line, then tried to access a url that does
not require password, then it works mean.

Can you detect any issue with the way I pass the auth token to GitHub?

Please note that I cannot use any of the new GitHub modules on CPAN, hence
my own implementation.

Any pointer appreciated.

mimi

Reply via email to