#1518·pgcli

启动程序在 `TypeError: replace() 参数 2 必须是 str,而不是 bytes` 后发生崩溃,然后是 `TypeError: 不能在 bytes 型对象上使用字符串模式`

作者: mwbmcc创建于 2025年8月2日更新于 2026年9月1日
标签bug

`pgcli` crashed 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) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Server: PostgreSQL 17.5 (Homebrew) 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) …