彷徨うおのこ

死ぬまで死なないぜ おれは

azure_sdk_pythonでget_regionしようとしたらKeyring cache token has failed: No recommended backend was available. Install the keyrings.alt package if you want to use the non-recommended backends. See README.rst for details.


azureで

Keyring cache token has failed: No recommended backend was available. Install the keyrings.alt package if you want to use the non-recommended backends. See README.rst for details.


というエラーが出るときの対処。

1.secretstorageが入ってないよ

参考
https://github.com/jaraco/keyring/issues/258

>>That means you dont have the SecretStorage package installed. You should pip install secretstorage
とのこと。
#pip install secretstorage
[root@xxxx azure]# pip install secretstorage
Requirement already satisfied: secretstorage in /root/.pyenv/versions/3.5.2/lib/python3.5/site-packages (3.0.1)
Requirement already satisfied: jeepney in /root/.pyenv/versions/3.5.2/lib/python3.5/site-packages (from secretstorage) (0.3.1)
Requirement already satisfied: cryptography in /root/.pyenv/versions/3.5.2/lib/python3.5/site-packages (from secretstorage) (2.2.2)
Requirement already satisfied: asn1crypto>=0.21.0 in /root/.pyenv/versions/3.5.2/lib/python3.5/site-packages (from cryptography->secretstorage) (0.24.0)
Requirement already satisfied: six>=1.4.1 in /root/.pyenv/versions/3.5.2/lib/python3.5/site-packages (from cryptography->secretstorage) (1.10.0)
Requirement already satisfied: idna>=2.1 in /root/.pyenv/versions/3.5.2/lib/python3.5/site-packages (from cryptography->secretstorage) (2.1)
Requirement already satisfied: cffi>=1.7; platform_python_implementation != "PyPy" in /root/.pyenv/versions/3.5.2/lib/python3.5/site-packages (from cryptography->secretstorage) (1.7.0)

Requirement already satisfied: pycparser in /root/.pyenv/versions/3.5.2/lib/python3.5/site-packages (from cffi>=1.7; platform_python_implementation != "PyPy"->cryptography->secretstorage) (2.14)

さて実行。
[root@xxxxx azure]# python get_region.py 
Keyring cache token has failed: No recommended backend was available. Install the keyrings.alt package if you want to use the non-recommended backends. See README.rst for details.
Accept header absent and forced to application/json
eastasia
southeastasia
centralus
eastus
eastus2
westus
northcentralus
southcentralus
northeurope
westeurope
japanwest
japaneast
brazilsouth
australiaeast
australiasoutheast
southindia
centralindia
westindia
canadacentral
canadaeast
uksouth
ukwest
westcentralus
westus2
koreacentral
koreasouth
francecentral
francesouth
australiacentral

australiacentral2
まだ出る。。。

2.keyrings.alt


Keyring cache token has failed: No recommended backend was available. Install the keyrings.alt package if you want to use the non-recommended backends. See README.rst for details.

入れりゃいいのか?

[root@z1tg7160-vm01 azure]# pip install keyrings.alt
Collecting keyrings.alt
Requirement already satisfied: six in /root/.pyenv/versions/3.5.2/lib/python3.5/site-packages (from keyrings.alt) (1.10.0)
Installing collected packages: keyrings.alt
Successfully installed keyrings.alt-3.1
実行

[root@z1tg7160-vm01 azure]# python get_region.py 
Accept header absent and forced to application/json
eastasia
southeastasia
centralus
eastus
eastus2
westus
northcentralus
southcentralus
northeurope
westeurope
japanwest
japaneast
brazilsouth
australiaeast
australiasoutheast
southindia
centralindia
westindia
canadacentral
canadaeast
uksouth
ukwest
westcentralus
westus2
koreacentral
koreasouth
francecentral
francesouth
australiacentral
australiacentral2
おお、なくなったぞ!

keyrings.altってなんぞや??

https://pypi.org/project/keyrings.alt/
Alternate keyring backend implementations for use with the keyring package.
Keyrings in this package may have security risks or other implications. These backends were extracted from the main keyring project to make them available for those who wish to employ them, but are discouraged for general production use. Include this module and use its backends at your own risk.


つまり、keyringという概念の代替的な実装であると。そして、セキュリティは低下するけどね、と。
しかし、Keyring cache tokenは成功するよ、と。

keyringを調べる。

Keyring is an optional sub-system that does not impact at all the Authentication. It's intended to store your token in a way that you can re-instanciate the credentials even if the Python process is gone, without talking again to AD. This does not block Authentication if the credentials is valid, this is just a warning log that if your Python process ends, you won't be able to re-create the Credentials class without re-asking a token to AD.

つまり、ついでにtokenを生成しているわけですね。で、コケているけど、optionalなものだから警告にとどめていると。