-
Notifications
You must be signed in to change notification settings - Fork 556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: cannot use a string pattern on a bytes-like object #1405
Comments
Thanks for reporting @jumpnett. If you're able to submit a PR, it will be very welcome. |
I'm experiencing the same error. Adding a few logs, I can see that |
I can replicate the error on my setup too. Thank you. @j-bennet Details: |
This may be occurring because your database/client's encoding is set to SQL_ASCII (which will prevent the underlying postgres library, psycopg, from decoding strings to Python str objects). Quick example: import psycopg
# Assuming you have PG* env vars set
with psycopg.connect() as conn:
result = conn.execute("SHOW SERVER_ENCODING").fetchone()
print(result)
result = conn.execute("SELECT 'str'").fetchone()[0]
print(conn.info.encoding, result, type(result))
with psycopg.connect("client_encoding=utf8") as conn:
result = conn.execute("SHOW SERVER_ENCODING").fetchone()
print(result)
result = conn.execute("SELECT 'str'").fetchone()[0]
print(conn.info.encoding, result, type(result))
|
A workaround for the issue was to force the client encoding to utf8 via an environment variable when launching pgcli like so
This isn't really a permanent solution, as it could result in trying to decode undecodable text from your database (since SQL_ASCII means it could contain anything, that's why psycopg won't decode it by default). As a full fix, It's probably reasonable for pgcli to force its own decoding of returned bytes in specific cases like this where it's essentially fetching postgres identifiers (in this case, the elements of the search path) which I would always expect to be decodable. Instead of doing its own decoding, pgcli could also temporarily set the client encoding to utf8 or similar (e.g. |
Description
When launching pgcli, I get the following error:
This error occurs when connecting to a PostgreSQL 9.3.4, but not a PostgreSQL 9.3.20 server.
Your environment
OS: Ubuntu 23.04 x86_64
pgcli Version: 3.5.0
pip freeze:
The text was updated successfully, but these errors were encountered: