Some text is being fetched from an nvarchar
column on a SQL Server database using SQLAlchemy and then written to a Postgres database with column type character varying
. Python throws the following exception when the source data contains the character :
UnicodeEncodeError: 'utf-8' codec can't encode character '\ud83d'
in position 34: surrogates not allowed
The SQLAlchemy column type is set to String
. I tried setting the column type to Unicode
and separately set the column collation to SQL_Latin1_General_CP1_CI_AS
, with no luck. The driver being used is FreeTDS.
Why can't Python encode this string? Does the problem lie with our use of SQLAlchemy, Python or Postgres? This error is making me .