habe folgenden Code:
Code: Alles auswählen
#!C:\Python\python.exe
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import subprocess
import os
import httplib2
import smtplib
import active_directory
import logging
import codecs
# KTT apiclient change into googleapiclient'''
from googleapiclient import discovery
from oauth2client import client
from oauth2client.file import Storage
from json import dumps
from email.mime.text import MIMEText
# 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 = 'C:\\Python\\Ownscripts\\client_secret.json'
APPLICATION_NAME = 'Directory API Python Quickstart'
# Open a plain text file for reading. For this example, assume that
# the text file contains only ASCII characters.
fp = codecs.open('C:\\Python\\Ownscripts\\textfile.txt', 'r')
msg_replace = fp.read()
msg_replace = msg_replace.replace("_Benutzerkennung_", sys.argv[1])
msg_replace = msg_replace.replace("_Anleger-UID_", sys.argv[3])
# Create a text/plain message
msg = MIMEText(msg_replace)
fp.close()
# Mail Konstanten
user = active_directory.find_user(str(sys.argv[1]))
CC_mail = active_directory.find_user(str(sys.argv[3]))
sender = mail@web.de
mailuser = mail1@web.de
msg['Subject'] = 'Google Account wurde angelegt.'
msg['From'] = sender
msg['To'] = mailuser
s = smtplib.SMTP('Server03')
ProxyInfo = httplib2.ProxyInfo(proxy_type=httplib2.socks.PROXY_TYPE_HTTP, proxy_host='Server01', proxy_port=8080,
proxy_user='$NWVM-PROXY', proxy_pass='Passwort')
def get_credentials():
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
print('Storing credentials to ' + credential_path)
return credentials
def main():
credentials = get_credentials()
http = credentials.authorize(httplib2.Http(proxy_info=ProxyInfo))
discovery.build('admin', 'directory_v1', http=http)
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": str(sys.argv[2]),
"changePasswordAtNextLogin": True,
"orgUnitPath": '''/''' + user.userPrincipalName.split("@", 1)[-1],
"primaryEmail": user.userPrincipalName,
"customerID": "my_customer",
"name": {"givenName": user.givenName, "familyName": user.sn}}
))
subprocess.call(
'runas.exe /user:XX-DD\$NWVMAD-USER /savecred "C:\Python\OwnScripts\ADUserGroup.cmd "' + str(sys.argv[1]))
s.sendmail(sender, [mailuser], msg.as_string('UTF-8'))
s.quit()
if __name__ == '__main__':
main()
Traceback (most recent call last):
File "C:\Python\Ownscripts\quickstart_ent.py", line 120, in <module>
main()
File "C:\Python\Ownscripts\quickstart_ent.py", line 95, in main
http = credentials.authorize(httplib2.Http(proxy_info=ProxyInfo))
AttributeError: 'NoneType' object has no attribute 'authorize'
Anscheinend kommt aus def get_credentials(): keine Inhalt zurück. Warum?
Danke für Eure Antwort
Gruß
Frank