startup crashes on `TypeError: replace() argument 2 must be str, not bytes`, followed by `TypeError: cannot use a string pattern on a bytes-like object`
Les mainteneurs répondent en général sous 1 jour
@DiegoDAF y travaille déjà.
Depuis le 1/9/2026.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 68/100
Piste de recherche
Reproduisez l’échec au démarrage avec pgcli 4.3.0 sur Python 3.13, puis lisez pgcli/main.py autour des lignes 1323-1324 de get_prompt et pgcli/completion_refresher.py autour de refresh_schemata. Suivez les valeurs transmises aux méthodes escaped_names et escape_name de pgcompleter.py ; c’est terminé lorsque le démarrage atteint le prompt sans les TypeErrors string/bytes signalées.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Installed pgcli 4.3.0 using pip install pgcli in a Python 3.13 venv (MacOS 15.x, recent Sequoia).
pgcli crashes on startup due to a string-handling error (or byte string-handling error). Superficial patches lead to deeper problems during startup.
First I tried to start pgcli with the command pgcli my_database_name
Got a stacktrace ending with this error, related to handling string versus bytes:
File "/path/to/my/venv/lib/python3.13/site-packages/pgcli/main.py", line 1051, in get_message
prompt = self.get_prompt(prompt_format)
File "/path/to/my/venv/lib/python3.13/site-packages/pgcli/main.py", line 1323, in get_prompt
string = string.replace("\\H", self.pgexecute.host or "(none)")
TypeError: replace() argument 2 must be str, not bytes
I modified line 1323 like this, and this initial error went away...
string = string.replace("\\H", str(self.pgexecute.host) or "(none)") # HACK added str() 20250802
...however then I got the same error from the subsequent line 1324:
File "/path/to/my/venv/lib/python3.13/site-packages/pgcli/main.py", line 1324, in get_prompt
string = string.replace("\\h", self.pgexecute.short_host or "(none)")
TypeError: replace() argument 2 must be str, not bytes
So I modified line 1324 the same way to bypass the error:
string = string.replace("\\h", str(self.pgexecute.short_host) or "(none)") # HACK added str() 20250802
These two hacks permitted pgcli to get farther in start up, however then I received another TypeError, seemingly related to the same issues. At this point I gave up debugging it. It should be an easy fix for someone who knows the pgcli codebase.
$ pgcli my_database_name
Using local time zone MyCountry/MyCity (server uses b'MyCountry/MyCity')
Use `set time zone <TZ>` to override, or set `use_local_timezone = False` in the config
Exception in thread completion_refresh:
Traceback (most recent call last):
File "/opt/homebrew/Cellar/[email protected]/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/threading.py", line 1043, in _bootstrap_inner
self.run()
~~~~~~~~^^
File "/opt/homebrew/Cellar/[email protected]/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/threading.py", line 994, in run
self._target(*self._args, **self._kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/my/venv/lib/python3.13/site-packages/pgcli/completion_refresher.py", line 67, in _bg_refresh
refresher(completer, executor)
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
Server: PostgreSQL 17.5 (Homebrew)
File "/path/to/my/venv/lib/python3.13/site-packages/pgcli/completion_refresher.py", line 108, in refresh_schemata
completer.set_search_path(executor.search_path())
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/my/venv/lib/python3.13/site-packages/pgcli/pgcompleter.py", line 335, in set_search_path
self.search_path = self.escaped_names(search_path)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
Version: 4.3.0
Home: http://pgcli.com
File "/path/to/my/venv/lib/python3.13/site-packages/pgcli/pgcompleter.py", line 183, in escaped_names
return [self.escape_name(name) for name in names]
~~~~~~~~~~~~~~~~^^^^^^
File "/path/to/my/venv/lib/python3.13/site-packages/pgcli/pgcompleter.py", line 164, in escape_name
(not self.name_pattern.match(name))
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
TypeError: cannot use a string pattern on a bytes-like object
Traceback (most recent call last):
File "/path/to/my/venv/bin/pgcli", line 8, in <module>
sys.exit(cli())
~~~^^
File "/path/to/my/venv/lib/python3.13/site-packages/click/core.py", line 1442, in __call__
return self.main(*args, **kwargs)
~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/path/to/my/venv/lib/python3.13/site-packages/click/core.py", line 1363, in main
rv = self.invoke(ctx)
File "/path/to/my/venv/lib/python3.13/site-packages/click/core.py", line 1226, in invoke
return ctx.invoke(self.callback, **ctx.params)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/my/venv/lib/python3.13/site-packages/click/core.py", line 794, in invoke
return callback(*args, **kwargs)
File "/path/to/my/venv/lib/python3.13/site-packages/pgcli/main.py", line 1720, in cli
pgcli.run_cli()
~~~~~~~~~~~~~^^
File "/path/to/my/venv/lib/python3.13/site-packages/pgcli/main.py", line 979, in run_cli
text = self.prompt_app.prompt()
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/shortcuts/prompt.py", line 1035, in prompt
return self.app.run(
~~~~~~~~~~~~^
set_exception_handler=set_exception_handler,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<2 lines>...
inputhook=inputhook,
^^^^^^^^^^^^^^^^^^^^
)
^
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/application/application.py", line 1002, in run
return asyncio.run(coro)
~~~~~~~~~~~^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 195, in run
return runner.run(main)
~~~~~~~~~~^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/application/application.py", line 886, in run_async
return await _run_async(f)
^^^^^^^^^^^^^^^^^^^
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/application/application.py", line 739, in _run_async
self._redraw()
~~~~~~~~~~~~^^
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/application/application.py", line 543, in _redraw
self.context.copy().run(run_in_context)
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/application/application.py", line 526, in run_in_context
self.renderer.render(self, self.layout)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/renderer.py", line 647, in render
layout.container.preferred_height(size.columns, size.rows).preferred,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/layout/containers.py", line 319, in preferred_height
c.preferred_height(width, max_available_height) for c in self._all_children
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/layout/containers.py", line 786, in preferred_height
return self.content.preferred_height(width, max_available_height)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/layout/containers.py", line 319, in preferred_height
c.preferred_height(width, max_available_height) for c in self._all_children
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/layout/containers.py", line 2623, in preferred_height
if self.filter():
~~~~~~~~~~~^^
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/filters/base.py", line 253, in __call__
return self.func()
~~~~~~~~~^^
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/shortcuts/prompt.py", line 161, in has_before_fragments
for fragment, char, *_ in get_prompt_text():
~~~~~~~~~~~~~~~^^
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/shortcuts/prompt.py", line 1280, in _get_prompt
return to_formatted_text(self.message, style="class:prompt")
File "/path/to/my/venv/lib/python3.13/site-packages/prompt_toolkit/formatted_text/base.py", line 82, in to_formatted_text
return to_formatted_text(value(), style=style)
~~~~~^^
File "/path/to/my/venv/lib/python3.13/site-packages/pgcli/main.py", line 1051, in get_message
prompt = self.get_prompt(prompt_format)
File "/path/to/my/venv/lib/python3.13/site-packages/pgcli/main.py", line 1324, in get_prompt
string = string.replace("\\h", self.pgexecute.short_host or "(none)")
TypeError: replace() argument 2 must be str, not bytes
- Langage dominant
- Python
- Étoiles
- 13.4k
- Forks
- 610
- Merge moyen
- 14 min
- PR mergées (30 j)
- 2
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de dbcli/pgcli
-
# is not as -- in PostgreSQLPeut-être pris @DiegoDAF l’a pris il y a 24 jours. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 64/100
dbcli/pgcli#1646 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Replace the pgclirc ConfigObj parser while preserving configuration compatibilityPeut-être pris @jackwalkerlabs l’a pris il y a 34 jours. Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 3/5 1-2 jours Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 3/5 1-2 jours Accessibilité débutants 55/100
dbcli/pgcli#1608 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 52/100
dbcli/pgcli#1607 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de dbcli/pgcli
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
common-workflow-language/cwl-utils#477 ·
Les mainteneurs répondent en général sous 1 jour
-
Add dependabotOuvertefeat
Difficulté 2/5 Moins d'une heure Accessibilité débutants 72/100
open-nudge/opentemplate#204 ·
Les mainteneurs répondent en général sous 1 jour
-
github-stale-ci-pr-closer: KV state is double-wrapped, never persists, and hits the depth-32 limitPeut-être pris @VascoSch92 l’a pris aujourd’hui. Ouvertepriority:medium ready-for-dev
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
OpenHands/extensions#781 ·
Les mainteneurs répondent en général sous 1 jour
-
bug good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
curriculum documentation quality
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
githubnext/gh-aw-workshop#4638 ·
Les mainteneurs répondent en général sous 1 jour