You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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认证。按以下步骤重新操作:

  1. 临时修改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
    
  2. 重启PostgreSQL服务,确保配置生效。
  3. 登录PostgreSQL:psql -U postgres
  4. 执行SQL命令强制生成MD5格式密码(替换<your_username>和<new_md5_password>为实际值):
    ALTER USER <your_username> WITH PASSWORD '<new_md5_password>';
    

    注意:优先用ALTER USER而非\password,避免命令缓存导致的加密格式异常。

  5. 确认password_encryption配置:
    SHOW password_encryption;
    
    确保返回值为md5。
  6. 将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
    
  7. 再次重启PostgreSQL服务。
  8. 修正Mapnik代码中的密码参数,填入实际设置的MD5密码(之前代码中password=''为空,需补全)。

额外提示:Mapnik 2.2.0依赖的libpq库版本较旧,本身不支持SCRAM认证,只要密码为MD5格式且pg_hba.conf配置正确,即可正常连接。

内容的提问来源于stack exchange,提问作者siphiwo bitterhout

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 09:56:21