erhalte wenn ich ein Pythonskript über ein Webformular als CGI anspreche folgende Fehlermeldung:
class 'pywintypes.com_error'>: (-2147352567, 'Ausnahmefehler aufgetreten.', (0, u'Provider', u'Klasse nicht registriert', None, 1240640, -2147221164), None)
Möglicherweise hat Python ein Problem mit der folgenden Zeile:
user = active_directory.find_user (form.getfirst('uid',""))
auch in abgewandelter Form funktioniert es nicht:
user = active_directory.find_user (form.getvalue('uid'))
Das Module active_directory funktioniert ohne Probleme.
Der Webserver ist ein Apache (in XAMPP) // XAMPP for Windows 7.0.13 // Windows 10 64 Bit // Python2.7 32 Bit/
Danke für die Unterstützung
Hier das Skript:
Code: Alles auswählen
#!C:\Temp\Python27\python.exe
#-*- coding: utf-8 -*-
from __future__ import print_function
import httplib2
import json
import os
import sys
sys.path.append('C:\Temp\Python27\0.6.7')
import active_directory
import cgi, cgitb
cgitb.enable()
form = cgi.FieldStorage()
s1=form.getfirst('uid',"")
s2=form.getvalue('passwort')
user = active_directory.find_user (form.getfirst('uid',""))
#KTT apiclient change into googleapiclient'''
from googleapiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
from json import loads, dumps
# If modifying these scopes, delete your previously saved credentials
# at ~/.credentials/admin-directory_v1-python-quickstart.json
SCOPES = 'https://www.googleapis.com/auth/admin.directory.user'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Directory API Python Quickstart'
def get_credentials():
"""Gets valid user credentials from storage.
If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.
Returns:
Credentials, the obtained credential.
"""
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'admin-directory_v1-python-quickstart.json')
store = Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if flags:
credentials = tools.run_flow(flow, store, flags)
else: # Needed only for compatibility with Python 2.6
credentials = tools.run(flow, store)
print('Storing credentials to ' + credential_path)
return credentials
def main():
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('admin', 'directory_v1', http=http)
content = http.request(
uri='https://www.googleapis.com/admin/directory/v1/users',
method='POST',
headers={'Content-Type': 'application/json; charset=UTF-8'},
body=dumps({"kind": "admin#directory#user",
"password": s2,
"changePasswordAtNextLogin": True,
"orgUnitPath": '''/''' + user.userPrincipalName.split("@",1)[-1],
"primaryEmail": user.userPrincipalName,
"customerID": "my_customer",
"name": {"givenName": user.givenName, "familyName": user.sn}
})
)
print (content)
if __name__ == '__main__':
main();
<class 'pywintypes.com_error'> Python 2.7.13: C:\Temp\Python27\python.exe
Wed Jan 18 20:28:50 2017
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
C:\Temp\xampp\cgi-bin\cgi_formular_auswertung.cgi in ()
16 s1=form.getfirst('uid',"")
17 s2=form.getvalue('passwort')
=> 18 user = active_directory.find_user (form.getfirst('uid',""))
19
20 #KTT apiclient change into googleapiclient'''
user undefined, active_directory = <module 'active_directory' from 'C:\Temp\xampp\cgi-bin\active_directory.pyc'>, active_directory.find_user = <function find_user>, form = FieldStorage(None, None, [MiniFieldStorage('uid'...MiniFieldStorage('submit', 'Account erstellen')]), form.getfirst = <bound method FieldStorage.getfirst of FieldStor...iniFieldStorage('submit', 'Account erstellen')])>
C:\Temp\xampp\cgi-bin\active_directory.py in find_user(name='DEJHFK10')
720
721 def find_user (name=None):
=> 722 return root ().find_user (name)
723
724 def find_computer (name=None):
global root = <function root>, ).find_user undefined, name = 'DEJHFK10'
C:\Temp\xampp\cgi-bin\active_directory.py in find_user(self=<_AD_domain_dns: LDAP://DC=business,DC=jungheinrich,DC=com>, name='DEJHFK10')
538 def find_user (self, name=None):
539 name = name or win32api.GetUserName ()
=> 540 for user in self.search ("sAMAccountName='%s' OR displayName='%s' OR cn='%s'" % (name, name, name), objectCategory='Person', objectClass='User'):
541 return user
542
user undefined, self = <_AD_domain_dns: LDAP://DC=business,DC=jungheinrich,DC=com>, self.search = <bound method _AD_domain_dns.search of <_AD_domain_dns: LDAP://DC=business,DC=jungheinrich,DC=com>>, name = 'DEJHFK10', objectCategory undefined, objectClass undefined
C:\Temp\xampp\cgi-bin\active_directory.py in search(self=<_AD_domain_dns: LDAP://DC=business,DC=jungheinrich,DC=com>, *args=("sAMAccountName='DEJHFK10' OR displayName='DEJHFK10' OR cn='DEJHFK10'",), **kwargs={'objectCategory': 'Person', 'objectClass': 'User'})
571 sql_string.append ("WHERE %s" % where_clause)
572
=> 573 for result in query ("\n".join (sql_string), Page_size=50):
574 yield AD_object (result.ADsPath.Value)
575
result undefined, global query = <function query>, "\n".join undefined, sql_string = ['SELECT *', u"FROM 'LDAP://DC=business,DC=jungheinrich,DC=com'", "WHERE sAMAccountName='DEJHFK10' OR displayName='...ND objectClass='User' AND objectCategory='Person'"], Page_size undefined
C:\Temp\xampp\cgi-bin\active_directory.py in query(query_string=u"SELECT *\nFROM 'LDAP://DC=business,DC=jungheinric...ND objectClass='User' AND objectCategory='Person'", **command_properties={'Page_size': 50})
308 command.CommandText = query_string
309
=> 310 recordset, result = command.Execute ()
311 while not recordset.EOF:
312 yield ADO_record (recordset)
recordset undefined, result undefined, command = <COMObject ADODB.Command>, command.Execute = <bound method CDispatch.Execute of <COMObject ADODB.Command>>
C:\Temp\xampp\cgi-bin\<COMObject ADODB.Command> in Execute(self=<COMObject ADODB.Command>, RecordsAffected=<PyOleMissing object>, Parameters=<PyOleMissing object>, Options=-1)
C:\Temp\Python27\lib\site-packages\win32com\client\dynamic.py in _ApplyTypes_(self=<COMObject ADODB.Command>, dispid=5, wFlags=1, retType=(9, 0), argTypes=((16396, 18), (16396, 17), (3, 49)), user='Execute', resultCLSID='{00001556-0000-0010-8000-00AA006D2EA4}', *args=(<PyOleMissing object>, <PyOleMissing object>, -1))
285
286 def _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, *args):
=> 287 result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
288 return self._get_good_object_(result, user, resultCLSID)
289
result undefined, self = <COMObject ADODB.Command>, self._oleobj_ = <PyIDispatch at 0x03049878 with obj>, self._oleobj_.InvokeTypes = <built-in method InvokeTypes of PyIDispatch object>, dispid = 5, global LCID = 0, wFlags = 1, retType = (9, 0), argTypes = ((16396, 18), (16396, 17), (3, 49)), args = (<PyOleMissing object>, <PyOleMissing object>, -1)
<class 'pywintypes.com_error'>: (-2147352567, 'Ausnahmefehler aufgetreten.', (0, u'Provider', u'Klasse nicht registriert', None, 1240640, -2147221164), None)
argerror = None
args = (-2147352567, 'Ausnahmefehler aufgetreten.', (0, u'Provider', u'Klasse nicht registriert', None, 1240640, -2147221164), None)
excepinfo = (0, u'Provider', u'Klasse nicht registriert', None, 1240640, -2147221164)
hresult = -2147352567
message = ''
strerror = 'Ausnahmefehler aufgetreten.'