Ich habe einen Windows-Server (Navision) bietet Web-Zugriff auf seine APIs durch Active Directory-Authentifizierung.
Ich versuche, eine Anfrage an den Webserver durch Active Directory-Authentifizierung zu stellen, indem ich einen externen Linux-basierten Host verwende.Python urllib2 Anfrage Active Directory-Authentifizierung ausnutzen
Ich erfolgreich authentifiziert mit python-ldap
Bibliothek.
import ldap
import urllib2
DOMAINHOST='domain_ip_host'
USERNAME='[email protected]'
PASSWORD='mycleanpassword'
URL='http://...'
conn = ldap.open(DOMAINHOST)
ldap.set_option(ldap.OPT_REFERRALS, 0)
try:
print conn.simple_bind_s(USERNAME, PASSWORD)
except ldap.INVALID_CREDENTIALS:
user_error_msg('wrong password provided')
Die Ausgabe ist in diesem Fall:
(97, [], 1, [])
eine erfolgreiche Authentifizierung entspricht.
Ich müsste diese erfolgreiche Authentifizierung ausnutzen, um mit dem Navision-Webdienst zu kommunizieren, z. mit urllib2
Bibliothek.
req = urllib2.Request(URL)
res = urllib2.urlopen(req)
Natürlich, da die Authentifizierung nicht ausgenutzt wird/angenommen, schlägt die Anforderung mit einem 401 Unauthorized
Fehler.
ich auch zu benutzen versucht python-ntlm
Bibliothek: ist
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, URL, USERNAME, PASSWORD)
# create the NTLM authentication handler
auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman)
# other authentication handlers
auth_basic = urllib2.HTTPBasicAuthHandler(passman)
auth_digest = urllib2.HTTPDigestAuthHandler(passman)
# disable proxies (if you want to stay within the corporate network)
proxy_handler = urllib2.ProxyHandler({})
# create and install the opener
opener = urllib2.build_opener(proxy_handler, auth_NTLM, auth_digest, auth_basic)
urllib2.install_opener(opener)
# retrieve the result
response = urllib2.urlopen(url)
print(response.read())
Auch in diesem Fall wird ein 401 Unauthorized
Fehler zur Verfügung gestellt.
Wie kann ich eine Webanforderung erfolgreich erstellen, indem ich den Benutzer mit Active Directory authentifiziere?