Mapnik渲染地图文件时遇PostGIS认证错误:不支持方法10
问题:Mapnik连接PostGIS时提示“authentication method 10 not supported”
我在渲染Mapnik文件时遇到以下错误:
Traceback (most recent call last): File "C:/Users/siphi/PycharmProjects/test2/kmgmap.py", line 29, in <module> roads_ds = mapnik.PostGIS(host='localhost', user='postgres', password='', dbname='kmg3', table='planet_osm_line') File "C:\mapnik-v2.2.0\python\2.7\site-packages\mapnik\__init__.py", line 430, in PostGIS return CreateDatasource(keywords) RuntimeError: Postgis Plugin: authentication method 10 not supported
连接字符串:'host=localhost dbname=kmg3 user=postgres connect_timeout=4'
我尝试将认证方式从scram-sha-256降级为md5,但仍收到相同错误。操作步骤如下:
- 在
postgresql.conf文件中将password_encryption改为md5 - 在
pg_hba.conf文件中将前3处scram-sha-256改为trust# "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust - 重启
postgresql服务 - 执行
psql -U postgres(无需输入密码) - 使用命令
\password username修改密码 - 在
pg_hba.conf文件中将前3处trust改为md5# "local" is for Unix domain socket connections only local all all md5 # IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 md5 - 重启
postgresql服务
目前不想升级PostgreSQL客户端软件,只想通过降级密码加密方式解决问题。
解决方案
问题核心是用户密码仍保留SCRAM加密哈希值,即便修改了password_encryption为md5,若未重新生成MD5格式密码,PostgreSQL仍会尝试用SCRAM认证。按以下步骤重新操作:
- 临时修改
pg_hba.conf为trust认证:# "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust - 重启PostgreSQL服务,确保配置生效。
- 登录PostgreSQL:
psql -U postgres - 执行SQL命令强制生成MD5格式密码(替换
<your_username>和<new_md5_password>为实际值):ALTER USER <your_username> WITH PASSWORD '<new_md5_password>';注意:优先用
ALTER USER而非\password,避免命令缓存导致的加密格式异常。 - 确认
password_encryption配置:
确保返回值为SHOW password_encryption;md5。 - 将
pg_hba.conf改回md5认证:# "local" is for Unix domain socket connections only local all all md5 # IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 md5 - 再次重启PostgreSQL服务。
- 修正Mapnik代码中的密码参数,填入实际设置的MD5密码(之前代码中
password=''为空,需补全)。
额外提示:Mapnik 2.2.0依赖的libpq库版本较旧,本身不支持SCRAM认证,只要密码为MD5格式且pg_hba.conf配置正确,即可正常连接。
内容的提问来源于stack exchange,提问作者siphiwo bitterhout
相关产品推荐
相关产品推荐

