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

LDAP连接报错LDAPSessionTerminatedByServerError:会话被服务器终止求助

Troubleshooting LDAP Session Terminated by Server Error

Let’s work through your LDAP connection issue together—here’s what I notice and how to fix it:

1. Immediate Red Flags in Your Code & Output

First, let’s spot the obvious mismatches and syntax errors that are likely triggering the server to terminate your session:

  • Password Syntax Issue: Your code uses password=user-pass—in Python, variable names can’t include hyphens. If this is a hardcoded password, it needs quotation marks (e.g., password="your-actual-password"). If it’s a variable, rename it to something like user_password to follow Python’s naming rules. A malformed password will definitely get your connection rejected.
  • Mismatched User DN: Your code specifies user='uid=admin,ou=people,dc=example,dc=org', but the connection output shows the server is seeing uid=admin,ou=people,dc=hadoop,dc=apache,dc=org. This means either your code has the wrong DN, or your LDAP server’s admin account lives under the dc=hadoop,dc=apache,dc=org tree. Using an incorrect DN will fail authentication and trigger a session termination.

2. Step-by-Step Fixes & Troubleshooting

Here’s how to resolve this:

  • Fix the Password First: Correct the password line to use valid Python syntax. For example:
    # If using a hardcoded password:
    password="your-admin-password"
    # If using a variable:
    user_password = "your-admin-password"
    password=user_password
    
  • Verify the Admin DN: Confirm the correct DN for your LDAP admin account using a command-line tool like ldapsearch:
    ldapsearch -x -b dc=example,dc=org '(uid=admin)'
    
    Replace dc=example,dc=org with your actual LDAP base DN. This will return the full, correct DN of the admin user—use that exact string in your code.
  • Check Server Connectivity: Ensure the LDAP server is running on localhost:33389. Test the port with nc or telnet:
    nc -zv localhost 33389
    
    If this fails, your LDAP service isn’t running or the port is blocked.
  • Enable Detailed Debugging: Modify your connection to raise exceptions and auto-bind immediately—this will give you clearer, specific error messages:
    from ldap3 import Server, Connection, ALL, SIMPLE
    
    server = Server(host='localhost', port=33389, use_ssl=False, get_info=ALL)
    # Use the correct DN and fixed password here
    conn = Connection(server, user='uid=admin,ou=people,dc=example,dc=org', password='your-admin-password', 
                      raise_exceptions=True, authentication=SIMPLE, auto_bind=True)
    
    print(server.info)
    print(conn)
    
    With raise_exceptions=True, you’ll get precise details about why the server is terminating the session (e.g., invalid credentials, missing permissions).

3. Additional Checks

  • Confirm the admin account has permission to connect from your host—some LDAP servers restrict connections to specific IP addresses.
  • Check the LDAP server’s logs (usually in /var/log/ldap/ or a similar directory) for more context on why the session was terminated.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 04:30:25