首页 > 解决方案 > 无论如何要使用 Python SDK 获取 azure Web 应用程序(Azure 函数应用程序)的 ftpsState 吗?

问题描述

问题是使用 python SDK 我无法列出与 Azure 函数应用程序相关的所有配置信息。因此,python SDK get_configration() API 不包含密钥 ftpsState。所以我想在我的回复中列出那个键。

我正在寻找可以解决我的问题的建议。

我已经为 Web 应用程序设置了 azure 客户端并调用了函数 get_configuration(),但是在响应中,我没有得到一个我必须依赖我的工作的字段。

我提到的 Python SDK 的参考。 https://docs.microsoft.com/en-us/python/api/azure-mgmt-web/azure.mgmt.web.operations.web_apps_operations.webappsoperations?view=azure-python#get-configuration-resource-group- name--name--custom-headers-none--raw-false----操作-配置-

我的回应是

[
  {
    'id': '/subscriptions/<mysubscription>/resourceGroups/fnf/providers/Microsoft.Web/sites/fnf/config/web',
    'type': 'Microsoft.Web/sites/config',
    'properties': {
      'managedPipelineMode': 'Integrated',
      'autoHealEnabled': False,
      'phpVersion': '5.6',
      'publishingUsername': '$fnf',
      'vnetName': '',
      'scmType': 'None',
      'detailedErrorLoggingEnabled': False,
      'linuxFxVersion': '',
      'experiments': {
        'rampUpRules': [

        ]
      },
      'loadBalancing': 'LeastRequests',
      'numberOfWorkers': 1,
      'cors': {
        'allowedOrigins': [
          'https://functions.azure.com',
          'https://functions-staging.azure.com',
          'https://functions-next.azure.com'
        ]
      },
      'http20Enabled': False,
      'nodeVersion': '',
      'webSocketsEnabled': True,
      'requestTracingEnabled': False,
      'alwaysOn': False,
      'logsDirectorySizeLimit': 35,
      'use32BitWorkerProcess': True,
      'netFrameworkVersion': 'v4.0',
      'minTlsVersion': '1.2',
      'virtualApplications': [
        {
          'preloadEnabled': False,
          'physicalPath': 'site\\wwwroot',
          'virtualPath': '/'
        }
      ],
      'pythonVersion': '',
      'remoteDebuggingVersion': 'VS2017',
      'localMySqlEnabled': False,
      'appCommandLine': '',
      'httpLoggingEnabled': False,
      'defaultDocuments': [
        'Default.htm',
        'Default.html',
        'Default.asp',
        'index.htm',
        'index.html',
        'iisstart.htm',
        'default.aspx',
        'index.php'
      ],
      'remoteDebuggingEnabled': False
    },
    'name': 'fnf'
  }
]

但是,如果我检查基于 Web 的 API 并从中调用类似的 API,我们会得到正确的响应。

我的网络基础参考 API:https ://docs.microsoft.com/en-us/rest/api/appservice/webapps/getconfiguration

及其回应

{
  "id": "/subscriptions/<mysubscription>/resourceGroups/fnf/providers/Microsoft.Web/sites/fnf/config/web",
  "name": "fnf",
  "type": "Microsoft.Web/sites/config",
  "location": "Central US",
  "properties": {
    "numberOfWorkers": 1,
    "defaultDocuments": [
      "Default.htm",
      "Default.html",
      "Default.asp",
      "index.htm",
      "index.html",
      "iisstart.htm",
      "default.aspx",
      "index.php"
    ],
    "netFrameworkVersion": "v4.0",
    "phpVersion": "5.6",
    "pythonVersion": "",
    "nodeVersion": "",
    "linuxFxVersion": "",
    "windowsFxVersion": null,
    "requestTracingEnabled": false,
    "remoteDebuggingEnabled": false,
    "remoteDebuggingVersion": "VS2017",
    "httpLoggingEnabled": false,
    "logsDirectorySizeLimit": 35,
    "detailedErrorLoggingEnabled": false,
    "publishingUsername": "$fnf",
    "publishingPassword": null,
    "appSettings": null,
    "metadata": null,
    "connectionStrings": null,
    "machineKey": null,
    "handlerMappings": null,
    "documentRoot": null,
    "scmType": "None",
    "use32BitWorkerProcess": true,
    "webSocketsEnabled": true,
    "alwaysOn": false,
    "javaVersion": null,
    "javaContainer": null,
    "javaContainerVersion": null,
    "appCommandLine": "",
    "managedPipelineMode": 0,
    "virtualApplications": [
      {
        "virtualPath": "/",
        "physicalPath": "site\\wwwroot",
        "preloadEnabled": false,
        "virtualDirectories": null
      }
    ],
    "winAuthAdminState": 0,
    "winAuthTenantState": 0,
    "customAppPoolIdentityAdminState": false,
    "customAppPoolIdentityTenantState": false,
    "runtimeADUser": null,
    "runtimeADUserPassword": null,
    "loadBalancing": 1,
    "routingRules": [],
    "experiments": {
      "rampUpRules": []
    },
    "limits": null,
    "autoHealEnabled": false,
    "autoHealRules": null,
    "tracingOptions": null,
    "vnetName": "",
    "siteAuthEnabled": true,
    "siteAuthSettings": {
      "enabled": null,
      "unauthenticatedClientAction": null,
      "tokenStoreEnabled": null,
      "allowedExternalRedirectUrls": null,
      "defaultProvider": null,
      "clientId": null,
      "clientSecret": null,
      "clientSecretCertificateThumbprint": null,
      "issuer": null,
      "allowedAudiences": null,
      "additionalLoginParams": null,
      "isAadAutoProvisioned": false,
      "googleClientId": null,
      "googleClientSecret": null,
      "googleOAuthScopes": null,
      "facebookAppId": null,
      "facebookAppSecret": null,
      "facebookOAuthScopes": null,
      "twitterConsumerKey": null,
      "twitterConsumerSecret": null,
      "microsoftAccountClientId": null,
      "microsoftAccountClientSecret": null,
      "microsoftAccountOAuthScopes": null
    },
    "cors": {
      "allowedOrigins": [
        "https://functions.azure.com",
        "https://functions-staging.azure.com",
        "https://functions-next.azure.com"
      ],
      "supportCredentials": false
    },
    "push": null,
    "apiDefinition": null,
    "apiManagementConfig": null,
    "autoSwapSlotName": null,
    "localMySqlEnabled": false,
    "managedServiceIdentityId": null,
    "xManagedServiceIdentityId": null,
    "ipSecurityRestrictions": null,
    "scmIpSecurityRestrictions": null,
    "scmIpSecurityRestrictionsUseMain": null,
    "http20Enabled": false,
    "minTlsVersion": "1.2",
    "ftpsState": "FtpsOnly",
    "reservedInstanceCount": 0,
    "preWarmedInstanceCount": null,
    "healthCheckPath": null
  }
}

self.my_client.web 是使用 python SDK 为 Web 应用程序创建的客户端。

def get_config(self, f_id):
    pf = p_id(f_id) #extract info in a dict
    cnf = self.my_client.web.web_apps.get_configuration(
            resource_group_name=pf['resource_group'],
            name=pf['resource_name'],
            subscription_id=pf.get('subscription')
    )
    return cnf

我期待带有键“ftpsState”的输出。

[
  {
    'id': '/subscriptions/<mysubscription>/resourceGroups/fnf/providers/Microsoft.Web/sites/fnf/config/web',
    'type': 'Microsoft.Web/sites/config',
    'properties': {
      'managedPipelineMode': 'Integrated',
      'autoHealEnabled': False,
      'phpVersion': '5.6',
      'publishingUsername': '$fnf',
      'vnetName': '',
      'scmType': 'None',
      'detailedErrorLoggingEnabled': False,
      'linuxFxVersion': '',
      'experiments': {
        'rampUpRules': [

        ]
      },
      'loadBalancing': 'LeastRequests',
      'numberOfWorkers': 1,
      'cors': {
        'allowedOrigins': [
          'https://functions.azure.com',
          'https://functions-staging.azure.com',
          'https://functions-next.azure.com'
        ]
      },
      'http20Enabled': False,
      'ftpsState': 'FtpsOnly',
      'nodeVersion': '',
      'webSocketsEnabled': True,
      'requestTracingEnabled': False,
      'alwaysOn': False,
      'logsDirectorySizeLimit': 35,
      'use32BitWorkerProcess': True,
      'netFrameworkVersion': 'v4.0',
      'minTlsVersion': '1.2',
      'virtualApplications': [
        {
          'preloadEnabled': False,
          'physicalPath': 'site\\wwwroot',
          'virtualPath': '/'
        }
      ],
      'pythonVersion': '',
      'remoteDebuggingVersion': 'VS2017',
      'localMySqlEnabled': False,
      'appCommandLine': '',
      'httpLoggingEnabled': False,
      'defaultDocuments': [
        'Default.htm',
        'Default.html',
        'Default.asp',
        'index.htm',
        'index.html',
        'iisstart.htm',
        'default.aspx',
        'index.php'
      ],
      'remoteDebuggingEnabled': False
    },
    'name': 'fnf'
  }
]

标签: pythonazureazure-web-app-serviceazure-functions

解决方案


我尝试成功重现您的问题,发现它是由当前软件包引起的,如果您通过or安装它们azure==4.0.0azure-mgmt-web==0.35.0则不支持该属性。您可以参考它的源代码及其版本来发现它。ftps_statepip install azurepip install azure-mgmt-website_config_resource.pyazure_4.0.0master

天蓝色 4.0.0 标签的 site_config_resource.py

在此处输入图像描述

master 分支的 site_config_resource.py

在此处输入图像描述

所以首先,你需要卸载azure-sdk-for-pythonvia pip的所有包,如下。

pip freeze > packages_uninstalled_requirements.txt
pip uninstall -r packages_uninstalled_requirements.txt -y

然后,您必须azure-mgmt-webazure-sdk-for-python源代码库安装软件包,如下所示。

git clone git://github.com/Azure/azure-sdk-for-python.git
cd azure-sdk-for-python
python setup.py install

cd sdk/appservice/azure-mgmt-web
python setup.py install

然后,运行我的示例代码并获得您想要的结果,如下所示。

from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.web import WebSiteManagementClient

subscription_id = '<your subscription id>'
credentials = ServicePrincipalCredentials(
    client_id='<your client id>',
    secret='<your client secret>',
    tenant='<your tenant id>'
)

resource_group_name = '<your resource group name>'
name = '<your webapp or function name>'

client = WebSiteManagementClient(credentials, subscription_id)
conf = client.web_apps.get_configuration(resource_group_name, name)
print(conf.name, conf.ftps_state)

在此处输入图像描述


推荐阅读