http://www.perlmonks.org?node_id=11159356

Bod has asked for the wisdom of the Perl Monks concerning the following question:

Having changed server from CentOS to Debian 12 and Perl version from 5.16.3 to 5.36.0, I am having lots of difficulties with character encoding. A topic I don't properly understand. This problem is currently manifesting itself as a failed Stripe webhook. The webhook was working fine before and now it isn't!

Stripe gives me this error:
Invalid encoding: ISO-8859-1

I have checked the Debian encoding (I think) and it says:

~# echo $LANG C.UTF-8

Here is a very cut-down version of my code to demonstrate the problem:

#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); use strict; use warnings; use utf8; use JSON; print "Content-type: application/json; charset=UTF-8\n\n"; print encode_json { 'testing' => 'some test', };

If I call the webhook endpoint in browser, I get the expected JSON output but Stripe gives me the encoding error.

Given that only two things have changed, server OS and Perl version, it must be one of these. Is there anything I need to do on the server to ensure that it is serving UTF-8 output correctly?

There are other problems that I think are unconnected, but wise monks may find helpful as they could have the same cause...