简体   繁体   中英

Azure ADAL for Python - model has no attribute 'acquire_token_with_username_password'

Giving Azure ADAL for Python a try. Getting this error when import adal.

import adal

Gives error

token_response = adal.acquire_token_with_username_password( 
    AttributeError: 'module' object has no attribute 'acquire_token_with_username_password'

I have downloaded most recent code from Github.

The README has sample code that uses acquire_token_with_username_password so it should be present.

What am I missing?

import adal
token_response = adal.acquire_token_with_username_password(
    'https://login.windows.net/ACTIVE_DIRECTORY_TENANT.onmicrosoft.com',
    'username@ACTIVE_DIRECTORY_TENANT.onmicrosoft.com',
    'password'
)

Got it sorted.

I had created a python file named adal.py that I was using to test adal.

Looks like adal module was looking at this file as application file?

After I renamed adal.py to adal_test.py it and delete its adal.pyc file now adal is working as expected.

According to your description and answer, I think the issue was caused by name clashes. Your old script name adal was clashed with the directory name of the package adal for Python.

It's very similar with the other SO thread ImportError: cannot import name Session, when using Azure SDK , please see my answer for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM