通过Python接口获取credential信息失败

weixin_38085230 2017-04-15 02:45:39

根据官方文档的信息http://azure-sdk-for-python.readthedocs.io/en/latest/quickstart_authentication.html,
使用了如下两种方法来获取credential信息
1)使用service principal

self.azure_credentials = ServicePrincipalCredentials(client_id=self.credentials['client_id'],
                           
secret=self.credentials['secret'],

                           
tenant=self.credentials['tenant'])
2)使用ad user/password
self.azure_credentials =


UserPassCredentials(self.credentials['ad_user'],
self.credentials['password'])
我分别申请了public azure和china azure的免费账号,发现,使用上面的方法对public azure进行操作时可以成功,但是对china azure操作时会失败。
针对china azure,我也参考了http://azure-sdk-for-python.readthedocs.io/en/latest/multicloud.html里面的信息,添加了authentication_endpoint和azure_endpoint的信息,但是还是失败。
代码信息如下:
from azure.common.credentials import UserPassCredentials
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
authentication_endpoint = 'https://login.chinacloudapi.cn/'
azure_endpoint = 'https://management.chinacloudapi.cn/'

credentials = UserPassCredentials(
    'user',
    'pwd',
    auth_uri=authentication_endpoint,
    resource=azure_endpoint
)


返回的错误信息如下:
Traceback (most recent call last):
  File "azure_testcn2.py", line 12, in <module>
    resource=azure_endpoint
  File "/usr/local/lib/python2.7/dist-packages/msrestazure/azure_active_directory.py", line 335, in __init__
    self.set_token()
  File "/usr/local/lib/python2.7/dist-packages/msrestazure/azure_active_directory.py", line 370, in set_token
    raise_with_traceback(AuthenticationError, "", err)
  File "/usr/local/lib/python2.7/dist-packages/msrest/exceptions.py", line 50, in raise_with_traceback
    raise error
msrest.exceptions.AuthenticationError: , InvalidClientIdError: (invalid_request) AADSTS50059: No tenant-identifying information found in either the request or implied by any provided credentials.
这个错误,个人感觉是说的没有tenant信息,但是、使用powershell的Login-AzureRmAccount -EnvironmentName AzureChinaCloud命令是可以得到tenant信息的






...全文
29 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧