Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultAzureCredential failed to retrieve a token from the included credentials #7

Closed
spedditi opened this issue Mar 11, 2023 · 12 comments · Fixed by #10
Closed

DefaultAzureCredential failed to retrieve a token from the included credentials #7

spedditi opened this issue Mar 11, 2023 · 12 comments · Fixed by #10

Comments

@spedditi
Copy link

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

When i run azd up ( part of predocs.ps1), i am getting following error and search index gptkbindex didn't get created as part of this process. I created gptkbindex manually. Data files are not getting uploaded to storage account.

Any log messages given by the failure

DefaultAzureCredential failed to retrieve a token from the included credentials.
Attempted credentials:
EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
Visit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot.this issue.
ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint.
SharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.
AzureCliCredential: Azure CLI not found on path
AzurePowerShellCredential: Az.Account module >= 2.2.0 is not installed
To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.
Traceback (most recent call last):
File "………...Documents\workspace\lia\azure-search-openai-demo\scripts\prepdocs.py", line 208, in
create_search_index()
File "………...Documents\workspace\lia\azure-search-openai-demo\scripts\prepdocs.py", line 146, in create_search_index
if args.index not in index_client.list_index_names():
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\core\paging.py", line 132, in next
return next(self._page_iterator)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\core\paging.py", line 76, in next
self._response = self._get_next(self.continuation_token)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\search\documents\indexes_generated\operations_indexes_operations.py", line 512, in get_next
pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\core\pipeline_base.py", line 205, in run
return first_node.send(pipeline_request) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\core\pipeline_base.py", line 69, in send
response = self.next.send(request)
^^^^^^^^^^^^^^^^^^^^^^^
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\core\pipeline_base.py", line 69, in send
response = self.next.send(request)
^^^^^^^^^^^^^^^^^^^^^^^
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\core\pipeline_base.py", line 69, in send
response = self.next.send(request)
^^^^^^^^^^^^^^^^^^^^^^^
[Previous line repeated 2 more times]
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\core\pipeline\policies_redirect.py", line 160, in send
response = self.next.send(request)
^^^^^^^^^^^^^^^^^^^^^^^
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\core\pipeline\policies_retry.py", line 474, in send
response = self.next.send(request)
^^^^^^^^^^^^^^^^^^^^^^^
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\core\pipeline\policies_authentication.py", line 115, in send
self.on_request(request)
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\core\pipeline\policies_authentication.py", line 92, in on_request
self._token = self._credential.get_token(*self._scopes)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\identity_credentials\default.py", line 168, in get_token
return super(DefaultAzureCredential, self).get_token(*scopes, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\identity_credentials\chained.py", line 101, in get_token
raise ClientAuthenticationError(message=message)
azure.core.exceptions.ClientAuthenticationError: DefaultAzureCredential failed to retrieve a token from the included credentials.
Attempted credentials:
EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
Visit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot.this issue.
ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint.
SharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.
AzureCliCredential: Azure CLI not found on path
AzurePowerShellCredential: Az.Account module >= 2.2.0 is not installed
To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.

Expected/desired behavior

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

@spedditi
Copy link
Author

update, I fixed AzureCli issue. But now getting Authorization failed error

Traceback (most recent call last):
File "………...Documents\workspace\lia\azure-search-openai-demo\scripts\prepdocs.py", line 208, in
create_search_index()
File "………...Documents\workspace\lia\azure-search-openai-demo\scripts\prepdocs.py", line 146, in create_search_index
if args.index not in index_client.list_index_names():
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\core\paging.py", line 132, in next
return next(self._page_iterator)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\core\paging.py", line 76, in next
self._response = self._get_next(self.continuation_token)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "………...AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\search\documents\indexes_generated\operations_indexes_operations.py", line 520, in get_next
raise HttpResponseError(response=response, model=error)
azure.core.exceptions.HttpResponseError: () Authorization failed.
Code:
Message: Authorization failed.

@spedditi
Copy link
Author

image

image

@JoeNSalloum
Copy link

Make sure the sourcepage field in your Search Service indexer is flagged as 'retrievable', looks like you may have created the index manually?

@davidcervigon
Copy link

Same here. azd credentials are not being used by ./scripts/prepdocs.py correctly. I have also tried to open a different PowerShell session, run "azd login" then .\scripts\prepdocs.ps1 manually

Ensuring search index gptkbindex exists
DefaultAzureCredential failed to retrieve a token from the included credentials.
Attempted credentials:
EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
Visit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot.this issue.
ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint.
SharedTokenCacheCredential: Azure Active Directory error '(invalid_grant) AADSTS700082: The refresh token has expired due to inactivity. The token was issued on 2022-11-16T23:36:02.7494127Z and was inactive for 90.00:00:00.
Trace ID: 449a7461-1dbd-44c8-b226-f3b8674f0200
Correlation ID: 96f0545b-708f-4523-b819-f98b91adc661
Timestamp: 2023-03-12 00:55:11Z'
Content: {"error":"invalid_grant","error_description":"AADSTS700082: The refresh token has expired due to inactivity. The token was issued on 2022-11-16T23:36:02.7494127Z and was inactive for 90.00:00:00.\r\nTrace ID: 449a7461-1dbd-44c8-b226-f3b8674f0200\r\nCorrelation ID: 96f0545b-708f-4523-b819-f98b91adc661\r\nTimestamp: 2023-03-12 00:55:11Z","error_codes":[700082],"timestamp":"2023-03-12 00:55:11Z","trace_id":"449a7461-1dbd-44c8-b226-f3b8674f0200","correlation_id":"96f0545b-708f-4523-b819-f98b91adc661","error_uri":"https://login.microsoftonline.com/error?code=700082"}
To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.

I solved the issue by installing Az module in PowerShell 7:

Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force

Then running:

connect-azaccount
.\scripts\prepdocs.ps1

@jhuims
Copy link

jhuims commented Mar 14, 2023

I have tried to install AZ module for powershell 7 as davidcervigon mentioned, not work for me. My quick workaround is ..

open up prepdocs.ps1, add the --searchkey parameter , this searchkey can grab from portal under Cognitive Search resource.

python ./scripts/prepdocs.py '.\data\*' --searchkey xxxx --storageaccount $env:AZURE_STORAGE_ACCOUNT....

I do it while resources are spinning up before the execution of prepdocs.ps1 .

@spedditi
Copy link
Author

@jhuims @davidcervigon @JoeNSalloum can you share your azure search field screen. I am getting this error (Error: unsupported operand type(s) for +: 'NoneType' and 'str' ), i think search results are null . Thank you

image
image
image

@davidcervigon
Copy link

Hi

@spedditi , here it goes

image

I was able to bring more pdfs by running prepdocs.ps1 again

@vhvb1989
Copy link
Contributor

@spedditi, This PR fixes this issue: #10
In case you want to try it.

The prepdocs.py should use the same auth as azd, instead of letting folks to figure out how to set the DefaultAzureCredential for auth.

@vhvb1989
Copy link
Contributor

@spedditi I am closing this after #10
Please re-open if you keep getting this error

@EMiller124
Copy link

@vhvb1989 I am continuing to get this error. Like others have said, there is no error code and the message is just 'Authorization failed.'

I've checked and Form Reader and Blob Storage work fine, the only problem is when trying to connect to Cognitive Search

@vhvb1989
Copy link
Contributor

@EMiller124 , have you tried using latest changes from the repo? a search-role was recently added (https://github.com/Azure-Samples/azure-search-openai-demo/blob/main/infra/main.bicep#L271). Can you check if you have this changes on your end?

@EMiller124
Copy link

@vhvb1989 I did not have that bit actually. I got it working with the work around of using searchkey mentioned above but if I run into another issue I'll add that in as well. Thank you!

myh-st pushed a commit to myh-st/azure-search-openai-demo that referenced this issue Jun 2, 2023
myh-st pushed a commit to myh-st/azure-search-openai-demo that referenced this issue Jun 2, 2023
dantelmomsft added a commit to dantelmomsft/azure-search-openai-demo-java that referenced this issue Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants