Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 无法从Azure python函数验证Azure Web App_Python 3.x_Azure Web App Service - Fatal编程技术网

Python 3.x 无法从Azure python函数验证Azure Web App

Python 3.x 无法从Azure python函数验证Azure Web App,python-3.x,azure-web-app-service,Python 3.x,Azure Web App Service,我已经创建了一个azure python函数,需要从中连接webapp客户端 下面是我的azure python函数代码 import logging from azure.identity import ManagedIdentityCredential from azure.mgmt.resource import SubscriptionClient import azure.functions as func from azure.mgmt.web import WebSiteManag

我已经创建了一个azure python函数,需要从中连接webapp客户端

下面是我的azure python函数代码

import logging
from azure.identity import ManagedIdentityCredential
from azure.mgmt.resource import SubscriptionClient
import azure.functions as func
from azure.mgmt.web import WebSiteManagementClient
from azure.mgmt.web import WebSiteManagementClientConfiguration
from  azure.mgmt.web.models import SiteAuthSettings


def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    credentials = ManagedIdentityCredential()
    subscription_client = SubscriptionClient(credentials)
    subscription = next(subscription_client.subscriptions.list())
    subscription_id = subscription.subscription_id

    web_app_client = WebSiteManagementClient(credentials=credentials, subscription_id=subscription_id)

    for i in web_app_client.web_apps.list():
        print ("===================")
        print (i.resource_group)
        print (i.repository_site_name)
        print ("===================")
        get_auth = web_app_client.web_apps.get_auth_settings(i.resource_group, i.repository_site_name)
        if get_auth.enabled == False:
            print ("Auth Method is not enabled on: {} Web APP, Auth method will be enabled!!".format(i.repository_site_name))
            print (get_auth.enabled)
            web_app_client.web_apps.update_auth_settings(i.resource_group, i.repository_site_name, site_auth_settings=SiteAuthSettings(enabled=True, default_provider='AzureActiveDirectory'))
            print ("Auth Method is now enabled on: {} Web APP!!".format(i.repository_site_name))
        else:
            print ("Auth Method is Already enabled on: {} Web App".format(i.repository_site_name))
    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
            "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
            status_code=200
        )

当运行代码时,我得到下面的错误

**
Result: Failure Exception: AttributeError: 'ManagedIdentityCredential' object has no attribute 'signed_session' 
Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 343, in _handle__invocation_request 
call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.8/concurrent/futures/thread.py", 
line 57, in run result = self.fn(*self.args, **self.kwargs) 
File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 480, in __run_sync_func return func(**params) 
File "/home/site/wwwroot/web-app-auth-enable/__init__.py", line 19, in main for i in web_app_client.web_apps.list(): 
File "/home/site/wwwroot/.python_packages/lib/site-packages/msrest/paging.py", line 143, in __next__ self.advance_page() 
File "/home/site/wwwroot/.python_packages/lib/site-packages/msrest/paging.py", line 129, 
in advance_page self._response = self._get_next(self.next_link) 
File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/mgmt/web/v2019_08_01/operations/_web_apps_operations.py", 
line 95, in internal_paging response = self._client.send(request, stream=False, **operation_config) 
File "/home/site/wwwroot/.python_packages/lib/site-packages/msrest/service_client.py", 
line 336, in send pipeline_response = self.config.pipeline.run(request, **kwargs) 
File "/home/site/wwwroot/.python_packages/lib/site-packages/msrest/pipeline/__init__.py", line 197, in run return first_node.send(pipeline_request, **kwargs) 
# type: ignore File "/home/site/wwwroot/.python_packages/lib/site-packages/msrest/pipeline/__init__.py", 
line 150, in send response = self.next.send(request, **kwargs) 
File "/home/site/wwwroot/.python_packages/lib/site-packages/msrest/pipeline/requests.py", 
line 65, in send self._creds.signed_session(session)
**

看起来你为此打开了一个github问题:-在我看来他们回答了你的问题