I have the following code:
...
sub setImage {
my $self=shift;
my $filename=shift;
unless(-r $filename) {
warn "File $filename not found";
return;
}
my $imgn=shift;
my $operation=&URI::Escape::uri_escape_utf8(
(shift) ? "Удалить! (Delete)" : "Сохранить! (Store)");
my $FH=&::File::open($filename, 0, 0);
my $image;
# &utf8::downgrade($image);
sysread($FH, $image, 102400, 0);
close $FH;
my $imginfo=eval{&Image::Info::image_info(\$image)};
if($@ or $imginfo->{"error"}) {
warn "Invalid image: ".($@ || $imginfo->{"error"});
return undef;
}
my $fields=[
DIR => $self->url("fl"),
OPERATION => $operation,
FILE_NAME => ".photo$imgn",
# FILE => [$filename],
FILE => [undef, "image.".$imginfo->{"file_ext"},
# Content_Type => $imginfo->{"file_media_type"},
# Content_Type => 'application/octet-stream',
Content => $image,
],
];
my $response=&ZLR::UA::post(
&ZLR::UA::absURL("/cgi-bin/file_manager")."",
$fields,
Content_Type => "form-data",
);
print $response->decoded_content;
}
...
When I try to use function setImage it fails with error HTTP::Message content must be bytes at /usr/lib64/perl5/vendor_perl/5.8.8/HTTP/Request/Common.pm line 91
. Worse that I can't reproduce this error without using all of my code and upgrading libwww-perl does nothing. What can cause it?
Versions of libww-perl: dev-perl/libwww-perl-5.836. HTTP::Request and HTTP::Request::Common came from libwww-perl package, versions: 5.827 and 5.824.
Trace:
HTTP::Message content must be bytes at /usr/lib64/perl5/vendor_perl/5.8.8/HTTP/Request/Common.pm line 91
at Carp::croak(unknown source)
at HTTP::Message::__ANON__(/usr/lib64/perl5/vendor_perl/5.8.8/HTTP/Message.pm:16)
at HTTP::Message::_set_content(/usr/lib64/perl5/vendor_perl/5.8.8/HTTP/Message.pm:136)
at HTTP::Message::content(/usr/lib64/perl5/vendor_perl/5.8.8/HTTP/Message.pm:125)
at HTTP::Request::Common::POST(/usr/lib64/perl5/vendor_perl/5.8.8/HTTP/Request/Common.pm:91)
at LWP::UserAgent::post(/usr/lib64/perl5/vendor_perl/5.8.8/LWP/UserAgent.pm:397)
at ZLR::UA::post(./zlrchecker.pl:71)
at ZLR::Info::setImage(./zlrchecker.pl:1754)
at main::main(./zlrchecker.pl:3893)
at main::(./zlrchecker.pl:4148)
Use Devel::SimpleTrace and paste the trace. Install the module with cpan. Then run your program with
-MDevel::SimpleTrace
likeperl -MDevel::SimpleTrace ./myapp_run.pl
And paste the version of
HTTP::Request:Common
,HTTP::Message
, andLWP
.My guess is you'll see this in the stack trace:
This seems to be the code likely causing the error:
The docs in utf8 say this:
You should be able to make a test case by running
utf8::downgrade($http_message_content)