我的目标是通过带有 SSPI 的 NTLM 对使用 Python 3.5.2 中的请求库 (2.11.1) 的客户端进行身份验证,以便用户不必手动输入其域凭据(用于登录 PC)。
我发现了以下可能性,但没有一个对我有用:
HttpNtlmSspiAuth在请求中引发异常:
从 requests_ntlm 导入请求导入 HttpNtlmAuth、HttpNtlmSspiAuth
requests.get(site_url, auth=HttpNtlmSspiAuth())
requests-sspi-ntlm总是得到 401:
从 requests_sspi_ntlm 导入请求导入 HttpNtlmAuth
session = requests.Session() session.auth = HttpNtlmAuth() session.get(" http://ntlm_protected_site.com ")
并且requests-negotiate-sspi也会在请求中触发异常:
从 requests_negotiate_sspi 导入请求导入 HttpNegotiateAuth
r = requests.get(' https://iis.contoso.com ', auth=HttpNegotiateAuth())
难道我做错了什么?
我想在运行python脚本时在控制台中强制使用QuickEdit Mode,然后在终止之前禁用它.有没有办法做到这一点?
我有这个带有PyQt5的Python 3.5.1程序,以及一个从QtCreator ui文件创建的GUI,其中pyqtSlot装饰器导致“ TypeError:在textChanged(QString)和edited()之间发生connect()失败”。
在重现该问题的示例代码中,我有2个自定义类:MainApp和LineEditHandler。MainApp实例化主GUI(来自文件“ mainwindow.ui”),并且LineEditHandler处理QLineEdit对象。LineEditHandler存在的原因是将与QLineEdit对象主要相关的自定义方法集中在一个类中。它的构造函数需要QLineEdit对象和MainApp实例(在需要时访问其他对象/属性)。
在MainApp中,我将QLineEdit的textChanged信号连接到LineEditHandler.edited()。如果我不使用pyqtSlot()装饰LineEditHandler.edited(),则一切正常。如果我确实对方法使用@pyqtSlot(),则代码运行将失败,并显示“ TypeError:textChanged(QString)和edited()之间的connect()失败”。我在这里做错什么了吗?
您可以在以下位置获取mainwindow.ui文件:https ://drive.google.com/file/d/0B70NMOBg3HZtUktqYVduVEJBN2M/view
这是产生问题的示例代码:
import sys
from PyQt5 import uic
from PyQt5.QtWidgets import *
from PyQt5.QtCore import pyqtSlot
Ui_MainWindow, QtBaseClass = uic.loadUiType("mainwindow.ui")
class MainApp(QMainWindow, Ui_MainWindow):
def __init__(self):
# noinspection PyArgumentList
QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
# Instantiate the QLineEdit handler.
self._line_edit_handler = LineEditHandler(self, self.lineEdit)
# Let the QLineEdit handler deal with the QLineEdit textChanged signal.
self.lineEdit.textChanged.connect(self._line_edit_handler.edited)
class LineEditHandler:
def __init__(self, main_window, line_edit_obj):
self._line_edit = line_edit_obj
self._main_window = main_window
# FIXME The pyqtSlot decorator causes …Run Code Online (Sandbox Code Playgroud) 我有一个 QMainWindow,其中的小部件排列在网格中。当窗口按预期调整大小时,它们都按比例调整大小,除了放置在 QGroupBox 内的小部件。QGroupBox 本身会调整大小,但里面的小部件只是停留在同一个地方。如果我在 QGroupBox 上应用布局,小部件将失去其原始位置。请注意,我将 .ui 文件与 PyQt4 一起使用。您可以在此处获取该文件。
这就是发生的事情:
我遇到了这个 QCoreApplication 问题,其中在 QObject 在 QThread 内完成执行后调用 input() 会导致无限循环打印到控制台“QCoreApplication::exec: 事件循环已在运行”。
在代码中,我创建了一个通用worker作为QObject,将其移动到QThread中(使用QThread的认可方式,而不是子类化它),然后在通用worker内执行另一个QObject(主类)函数。只要我在执行 Master 后不调用 input() ,一切就可以正常工作。请注意,如果我直接在工作线程中执行函数(而不是主实例的函数),也会出现问题。
这是重现该问题的示例代码:
import sys
from PyQt4.QtCore import QCoreApplication, QObject, QThread, pyqtSignal, pyqtSlot
class Worker(QObject):
"""
Generic worker.
"""
start = pyqtSignal(str)
finished = pyqtSignal()
def __init__(self, function):
QObject.__init__(self)
self._function = function
self.start.connect(self.run)
def run(self):
self._function()
self.finished.emit()
class Master(QObject):
"""
An object that will use the worker class.
"""
finished = pyqtSignal()
def __init__(self):
QObject.__init__(self)
@pyqtSlot()
def do(self):
print("Do what?")
self.finished.emit()
def done():
# FIXME This will …Run Code Online (Sandbox Code Playgroud)