semifor / Net-Twitter

A Perl interface to the Twitter APIs
83 stars 37 forks source link

500 Can't connect to API #49

Closed jacoby closed 9 years ago

jacoby commented 9 years ago

I have code that I want to use all the time that uses Net::Twitter, but it has been giving me the above error on my Linux box. I adapted the code from the POD:

use feature qw{ state say } ;
use strict ;
use warnings ;
use utf8 ;
use Data::Dumper ;
use Net::Twitter ;
use Scalar::Util 'blessed' ;
my $nt = Net::Twitter->new(
    traits              => [ qw/API::RESTv1_1/ ],
    consumer_key        => 'No' ,
    consumer_secret     => 'No' ,
    access_token        => 'No' ,
    access_token_secret => 'Trust me, I put real values in' ,
    ssl                 => 1
    ) ;
my $result = $nt->update( 'Hello, world! ' . time ) ;
say Dumper $result ; 
exit ;

When I run it on another machine, I get successful tweets. When I run it on the machine I'm behind 8 hours a day, I get:

jacoby@oz:~$ dev/t_test.pl 500 Can't connect to api.twitter.com:443 at dev/t_test.pl line 22jacoby@oz:~$

Where line 22 is the one with $nt->update() in it.

It keeps happening to me. I installed perlbrew to get around it, and it worked for a while, then didn't. The error doesn't give me enough information to figure it out myself. Help?

semifor commented 9 years ago

Add the following code just before the update call. Maybe dumping the full response will shed some light on it.

$nt->ua->add_handler(request_done => sub {
    my $response = shift;
    print $response->as_string;
    return $response;
});

Twitter requires an SSL connection, so it might be something in the SSL handling that's different between the machines. Make sure you have current versions of IO::Socket::HTTPS and Net::SSL.

Technically, those should be optional dependencies for Net::Twitter since it can be used with Twitter compatible services that don't require SSL. But it looks like I may have inadvertently dropped the dependency when I switched to Distzilla for packaging.

You mention the system is in a different time zone. Be sure the system clock is accurate. OAuth relies on a reasonably accurate timestamps. You're don't seem to be getting far enough here for that to be the issue, though.

jacoby commented 9 years ago

If, instead, you mean IO::Socket::SSL, just installed them and got 'em working.

Thank you.

semifor commented 9 years ago

Indeed, I did. The alphabet soup of HTTPS/SSL modules keeps me confused.