Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1raK0R-009Csp-V4 for psycopg@arkaria.postgresql.org; Wed, 14 Feb 2024 18:29:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1raK0Q-007xoP-M5 for psycopg@arkaria.postgresql.org; Wed, 14 Feb 2024 18:29:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1raK0Q-007xoH-FG for psycopg@lists.postgresql.org; Wed, 14 Feb 2024 18:29:14 +0000 Received: from mail-oa1-x34.google.com ([2001:4860:4864:20::34]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1raK0N-007CFg-TZ for psycopg@postgresql.org; Wed, 14 Feb 2024 18:29:13 +0000 Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-214def5da12so49168fac.2 for ; Wed, 14 Feb 2024 10:29:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707935350; x=1708540150; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=4nq+TYWpKFtD7AVf0AuCCsxnczyz9KEf4XIMrA4Dl2o=; b=bEh+6utCrpgXzeX7PCTlHfNhNs2XNdiPC5aBDHUscxaIIXyY5KS9jDQcGBCF0iYWuh bABI4g8S7k4qBVyYWsmHAisBKfG/dBIZhn9gLHfRIZEaYD0pRnJphzIcalrJPFmw7Ph7 rhnfiIO+mDGtdQ0unPcVdWB2x2oj0r6+QTGh0J6OKMqrfs49eVovel84i2/8bOdc+YlD BZTv5etpZD/zNeUJF6fP7iZ+mU3ZlhdECsjsuOFt9KOsZgaxE+dXRXbyRH8l+vk+OAxi vmNQenukzxd/IsIv5p/qe0R3VdZ8qZjLkul+UOQpYinf4mpVmtaRcBD+IsDAkxsrfpq7 o7qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707935350; x=1708540150; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4nq+TYWpKFtD7AVf0AuCCsxnczyz9KEf4XIMrA4Dl2o=; b=oWTlqQBLBNn/bRfEvnq64YzP2srq0NJSOXoqk2mIDymrissazfxHgV/ae//urJ3Vf/ MMHqub5/1TgO3XKBwlFSX9Ueo9ugg3nHzNki3lcE28CLaDtgz7se+wdbxRau0yjU/4Ma z698Z993sXuDw5kCf2W7ZQtwt4H8yVF4LQs3nRAKfAndgNGnG35heZS6wOhdXIpqlssL dOzbPMQHjLvl9ek1DLRZwwp6vQoGyDYqEvV2nL3K5hdjOm1Q/WRgtwmQWYIVerm01FwU fUb76vi4FARK4bY+SoJZ42RvvUkFPlQBYEsbwka94tmCbab+wcq/lYxcu/Nen+nLK1JP 7KfA== X-Gm-Message-State: AOJu0YxyDUMp7CMpjjXFQOI4WkrS9fXnYB3Ri1S0CIfPhwdKJIMH3Rbz /cMbpQ9qWcLiIjeC7nCUAKtayZpUjtxiPznUd6lPg9wK6nBbXK+ov+ps0hI9XX3XzI8Yi1e+sUy m74cpsbgoNTWHB4qOeSnigYsb7As= X-Google-Smtp-Source: AGHT+IH1hndHB2HlddKylFiRPGM1QQlrVYguMhYSsOsIas2zLA95Qtcp+3bxQ4Hr3tPrUoNfzkrrAQE8kBU5mmVZ3pM= X-Received: by 2002:a05:6871:688:b0:21e:2338:aca6 with SMTP id l8-20020a056871068800b0021e2338aca6mr1151534oao.9.1707935350036; Wed, 14 Feb 2024 10:29:10 -0800 (PST) MIME-Version: 1.0 References: <20240213193732.28cb8329@slate.karlpinc.com> <20240214094203.52d7e22d@slate.karlpinc.com> In-Reply-To: <20240214094203.52d7e22d@slate.karlpinc.com> From: Daniele Varrazzo Date: Wed, 14 Feb 2024 19:28:57 +0100 Message-ID: Subject: Re: Reporting UnicodeEncodeError info on arbitrary data sent to PG with psycopg3 To: "Karl O. Pinc" Cc: "psycopg@postgresql.org" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, On Wed, 14 Feb 2024 at 16:42, Karl O. Pinc wrote: > I did not use conn.info.encoding because the docs say that it > contains the _client_ encoding, not the server-side encoding > used to store the db content. > [...] > Confirming the encodings, connecting to the "latin1" db with psql shows: > kop_latin1=> show client_encoding; > UTF8 > > kop_latin1=> show server_encoding; > LATIN1 > > But, conn.info.encoding does return iso8859-1. > > So I think your documentation has confused client > and server in this case. If you can confirm this > for me I'll go ahead and use conn.info.encoding. No, I am pretty sure that this is the client encoding that is reported. It comes from here: https://github.com/psycopg/psycopg/blob/ef6941df5b94997f79b429347c5d9b84e600bdd3/psycopg/psycopg/_encodings.py#L100-L101 which is a wrapper for PQparameterStatus: https://www.postgresql.org/docs/current/libpq-status.html#LIBPQ-PQPARAMETERSTATUS (so that the setting can be retrieved without running a query). Maybe the way you are connecting via psql sets the client_encoding? Can you try to get the result of `SHOW client_encoding` from psycopg?