pymssql Windows 身份验证 [英] pymssql windows authentication
问题描述
pymssql 模块用于支持 windows 身份验证.现在好像不行了.尽管在某些地方它仍然表明它应该起作用.我一直无法找到这个问题的明确答案,也没有解决方案.最相关的链接:
The pymssql module used to support windows authentication. Now it seems it does not. Though in some places it still shows that it should work. I have been unable to find a definitive answer to this problem, nor a solution. Most relevant link:
https://groups.google.com/forum/#!topic/pymssql/QDMLTGBNeU0
pymssql 1.0 支持它,因为它利用并依赖于MS 提供的 DLL,它是 SQL Server 客户端堆栈的一部分.这个stack 负责处理所有 NTLM 协商等.这意味着,除其他外,它是一个仅限 Windows 的解决方案.
pymssql 1.0 supported it because it made use of and depended on the MS-provided DLL which was part of the SQL Server client stack. This stack was in charge of handling all of the NTLM negotiation and such. This meant, among other things that it was a Windows-only solution.
我可以模拟多种网络环境,因此我尝试了许多不同的设置.我试图能够使用此脚本通过 Windows 身份验证连接到远程 MSSQL 服务器.这就是问题所在.
I can simulate many sorts of network environments so I have tried many different setups. I am trying to be able to use this script to connect to a remote MSSQL server using windows authentication. And this is the problem.
根据我的研究,包括上面的链接,有两种方法可以通过 pymssql 模块使用 windows 身份验证,应该可以工作.
According to my research, including the links above, there are two ways to use windows authentication with the pymssql module that are supposed to work.
第一种方法:使用当前用户凭据:
pymssql.connect(server='server')
# credentials come from active windows session
# some research shows that a "trusted=True" keyword should be provided.
第二种方法:使用给定的用户凭据:
pymssql.connect(server='server', user=r'domain\user', password='pass')
# credentials are given in code and somehow converted to a
# windows authentication in the background
# some research shows that a "trusted=True" keyword should be provided.
使用 _mssql
模块也是如此.
The same goes for using the _mssql
module.
注意:
- Python 版本:2.7.8
- 我使用的 pymssql 版本:2.1.1
- 曾经支持windows认证的pymssql版本:1.x
- 我已经测试过(所有 64 位):
- Windows 7 专业版
- Windows 7 家庭高级版
- Windows 服务器 2012
- Windows 服务器 2012R2
关于该主题的其他问题:
Other questions on the topic:
pymssql:如何在非 Windows 机器上运行时使用 Windows 身份验证
无法使用带有 Windows 身份验证的 pymssql 进行连接
https://stackoverflow.com/questions/27692366/mssql-python-windows-authentication一个>
推荐答案
所以,我想我应该用我最终用来解决这个问题的方法来回答我自己的问题(已经几个月了).
So, I figured I should answer my own question (it's been a few months) with the method that I ultimately used to solve this problem.
简短回答:我用过别的东西.
Short answer: I used something else.
更长的答案:为了测试 Windows 身份验证(除了当前登录的 Windows 用户,它确实有效)我开始使用
SQLCMD
来自微软的工具,结合PsExec
.Longer answer: For testing windows authentication (other than the currently logged on windows user, which does work) I started using
SQLCMD
tool from Microsoft, combined withPsExec
.我使用
elevated
(-h) 和load profile
(-e) 标志执行的 PsExec.使用完整的用户名DOMAIN\USERNAME
.The PsExec I executed with the
elevated
(-h) andload profile
(-e) flags. Using the full user nameDOMAIN\USERNAME
.我使用
trusted connection
-E 标志执行的 SQLCMD.The SQLCMD I executed with the
trusted connection
-E flag.剩下的就靠你了.
这篇关于pymssql Windows 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!