在 Windows 上使用 python 自动 NTLM [英] Automatic NTLM with python on Windows

查看:50
本文介绍了在 Windows 上使用 python 自动 NTLM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Windows 上使用来自 python 的自动 NTLM 身份验证?

How can I use automatic NTLM authentication from python on Windows?

我希望能够从 Windows 访问 TFS REST API,而无需对我的密码进行硬编码,就像我从 Web 浏览器(例如,firefox 的 network.automatic-ntlm-auth.trusted-uris)所做的一样.

I want to be able to access the TFS REST API from windows without hardcoding my password, the same as I do from the web browser (firefox's network.automatic-ntlm-auth.trusted-uris, for example).

推荐答案

我发现这个答案对我很有用因为:

I found this answer which works great for me because:

  1. 我只打算从 Windows 运行它,所以便携性不是问题
  2. 响应是一个简单的 json 文档,因此无需存储打开的会话

它使用 WinHTTP.WinHTTPRequest.5.1 COM 对象来处理本地身份验证:

It's using the WinHTTP.WinHTTPRequest.5.1 COM object to handle authentication natively:

import win32com.client
URL = 'http://bigcorp/tfs/page.aspx'    
COM_OBJ = win32com.client.Dispatch('WinHTTP.WinHTTPRequest.5.1')
COM_OBJ.SetAutoLogonPolicy(0)
COM_OBJ.Open('GET', URL, False)
COM_OBJ.Send()
print(COM_OBJ.ResponseText)

这篇关于在 Windows 上使用 python 自动 NTLM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆