Python 使用Google Directory API删除特定于应用程序的密码

Python 使用Google Directory API删除特定于应用程序的密码,python,google-api,google-admin-sdk,google-directory-api,google-python-api,Python,Google Api,Google Admin Sdk,Google Directory Api,Google Python Api,我已经为使用Google Directory API的用户编写了脚本/自动化了整个终止过程(即更改密码、移动到另一个OU等),这一切都很好,但是,我注意到,当我使用“”调用时,实际上没有任何ASP被删除。当我签入管理面板时,它们仍然存在于用户帐户中 我在脚本中做了十几个其他的GoogleAPI调用(这很有效),所以,不,这不是权限/范围问题。在脚本的ASP部分期间不会引发任何错误。它只是“处理”呼叫并继续。很奇怪 当我在Google上使用trythisapi部分时,它工作得很好,并且删除了我指定

我已经为使用Google Directory API的用户编写了脚本/自动化了整个终止过程(即更改密码、移动到另一个OU等),这一切都很好,但是,我注意到,当我使用“”调用时,实际上没有任何ASP被删除。当我签入管理面板时,它们仍然存在于用户帐户中

我在脚本中做了十几个其他的GoogleAPI调用(这很有效),所以,不,这不是权限/范围问题。在脚本的ASP部分期间不会引发任何错误。它只是“处理”呼叫并继续。很奇怪

当我在Google上使用trythisapi部分时,它工作得很好,并且删除了我指定的ASP

是否还有其他人遇到此问题

以下是相关代码的部分

scopes = ['https://www.googleapis.com/auth/admin.directory.user.security',
            'https://www.googleapis.com/auth/admin.directory.user',
            'https://www.googleapis.com/auth/gmail.settings.sharing',
            'https://www.googleapis.com/auth/gmail.modify',
            'https://www.googleapis.com/auth/admin.datatransfer',
            'https://www.googleapis.com/auth/admin.directory.group']

credentials = ServiceAccountCredentials.from_json_keyfile_name('../service-account-key.json', scopes=scopes)

delegated_credentials = credentials.create_delegated('REDACTED')
http_auth = delegated_credentials.authorize(Http())

directory_service = discovery.build('admin', 'directory_v1', http=http_auth)

def remove_asps():
    ##############################################################################################################################
    '''
    REMOVE ALL APP SPECIFIC PASSWORDS
    '''
    ##############################################################################################################################
    asp = directory_service.asps().list(userKey='{0}'.format(user_email)).execute()
    app_specific_passwords = asp.get('items', [])

    print('3) Removing App Specific Passwords:')
    if not app_specific_passwords:
        print('- {0} does not have any App Specific Passwords to remove.'.format(user_email))
        print('')
    else:
        for app_specific_password in app_specific_passwords:
            print('- Removing App Specific Password - {0} from {1}'.format(app_specific_password['name'],user_email))
            delete_asps = directory_service.asps().delete(userKey='{0}'.format(user_email),codeId='{0}'.format(app_specific_password['codeId']))
            print('Done.')
            print('')
我还尝试将值硬编码到调用中,并删除for循环,而不是使用变量,这也不起作用

日志显示调用已运行,但未引发任何错误:

googleapiclient.discovery: INFO     URL being requested: DELETE https://www.googleapis.com/admin/directory/v1/users/redacted_email/asps/0?
googleapiclient.discovery: INFO     URL being requested: DELETE https://www.googleapis.com/admin/directory/v1/users/redacted_email/asps/1?
googleapiclient.discovery: INFO     URL being requested: DELETE https://www.googleapis.com/admin/directory/v1/users/redacted_email/asps/2?

提前感谢您的帮助

请用最简单的代码更新问题,硬编码显示asp删除(失败案例)和更改密码(通过案例)。我认为这将帮助那些可能帮助回答问题的人。请用最简单的代码更新问题,硬编码显示asp删除(失败案例)和更改密码(通过案例)。我认为这将有助于那些有可能帮助回答问题的人。