相关疑难解决方法(0)

Python中的NTLM身份验证

我正在尝试使用python从Windows 7在IIS(Windows Server 2003)上实现NTLM身份验证.LAN Manager身份验证级别:仅发送NTLM响应.
客户端计算机和服务器位于同一个域中.
域控制器(AD)位于另一台服务器上(也运行Windows Server 2003).

我收到401.1 - 未经授权:由于凭据无效,访问被拒绝.你能帮我找出这个代码有什么问题和/或向我展示解决这个问题的其他可能方向(使用NTLM或Kerberos)吗?

import sys, httplib, base64, string
import urllib2
import win32api
import sspi 
import pywintypes
import socket

class WindoewNtlmMessageGenerator:
    def __init__(self,user=None):
        import win32api,sspi
        if not user:
            user = win32api.GetUserName()
        self.sspi_client = sspi.ClientAuth("NTLM",user)   

    def create_auth_req(self):
        import pywintypes
        output_buffer = None
        error_msg = None
        try:
            error_msg, output_buffer = self.sspi_client.authorize(None)            
        except pywintypes.error:
            return None
        auth_req = output_buffer[0].Buffer
        auth_req = base64.encodestring(auth_req)
        auth_req = string.replace(auth_req,'\012','')
        return auth_req 

    def create_challenge_response(self,challenge):
        import pywintypes
        output_buffer = None
        input_buffer …
Run Code Online (Sandbox Code Playgroud)

python authentication ntlm

19
推荐指数
2
解决办法
2万
查看次数

使用当前用户凭据授权 Python 脚本使用 NTLM 访问 SharePoint 列表

我有一个脚本,用于检查 SharePoint 列表中的特定文件修订版本并返回结果。这种方法效果很好,但目前我的授权方法要求我在代码中包含我自己的密码才能访问 SharePoint 列表,这并不理想,因为密码必须经常更新,并且其他用户可能会查看我的登录详细信息。

有人可以为我指明使用当前用户凭据访问 SharePoint 网站的正确方向吗?我一直在寻找 ActiveDirectory、NTLM、SOAP 等,但无法破译其中哪一个是最合适的方法。

我使用的是Python 2.7,工作函数如下:

import urllib2
from sharepoint import SharePointSite
from ntlm import HTTPNtlmAuthHandler

def read_sharepoint_list(current_project):
    # my Windows credentials
    username = "Domain\\user.name"
    password = "my_password"
    # the sharepoint info
    site_url = "http://SharePoint/"
    list_name = "My List"
    # an opener for the NTLM authentication
    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passman.add_password(None, site_url, username, password)
    auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman)
    # create and install the opener
    opener = urllib2.build_opener(auth_NTLM)
    urllib2.install_opener(opener)
    # create a SharePointSite object
    site = SharePointSite(site_url, …
Run Code Online (Sandbox Code Playgroud)

python sharepoint authorization ntlm

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

ntlm ×2

python ×2

authentication ×1

authorization ×1

sharepoint ×1