/Library/Perl/5.18/AnyEvent/Twitter/Stream.pm第126行意外结束字符串错误

时间:2015-12-15 14:14:55

标签: perl twitter

我在Perl中实现了一个小程序,打印一些推文到stdout。这是到目前为止的代码(为完整性而链接到previous question on this):

#!/usr/bin/perl
use strict;
use AnyEvent::Twitter::Stream;

if ($ENV{FIREHOSE_SERVER}) {
    $AnyEvent::Twitter::Stream::STREAMING_SERVER = $ENV{FIREHOSE_SERVER};
}

my $done = AE::cv;

binmode STDOUT, ":utf8";

my $streamer = AnyEvent::Twitter::Stream->new(
    consumer_key    => "my_consumer_key",
    consumer_secret => "my_consumer_secret",
    token           => "my_token",
    token_secret    => "my_token_secret",
    method   => "sample",
    use_compression => 1,
    on_tweet => sub {
        my $tweet = shift;
        print "$tweet->{user}{screen_name}: $tweet->{text}\n";
    },
    on_error => sub {
        my $error = shift;
        warn "ERROR: $error";
        $done->send;
    },
    on_eof   => sub {
        $done->send;
    },
);

$done->recv;

当我运行时,我通常(但并不总是)在屏幕上打印一条推文,然后立即出现此错误:

unexpected end of string while parsing JSON string, at character offset 892 (before "(end of string)") at /Library/Perl/5.18/AnyEvent/Twitter/Stream.pm line 126.

为什么会这样?它是否与推文的内容完全相关?如果是这样,有没有办法阻止脚本退出并继续监视流?

1 个答案:

答案 0 :(得分:4)

关闭压缩,根据this bug report版本在0.27版本中出现错误,可能会导致这类问题。

use_compression => 0