使用pythonsdk获取azure web应用程序(azure函数应用程序)的ftpsState是否仍然有效?

2024-07-07 08:33:40 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我在找一个能解决我问题的建议。你知道吗

我已经为web应用程序设置了azure客户端并调用函数get\u configuration(),但是在响应中,我没有得到一个必须依赖于我的工作的字段。你知道吗

pythonsdk的参考资料。 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----operation-config-

我的回答是

[
  {
    '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,我们就会得到正确的响应。你知道吗

我的web基础引用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
  }
}

你知道吗我的客户.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'
  }
]

Tags: namehttpscomwebidconfigfalsedefault
1条回答
网友
1楼 · 发布于 2024-07-07 08:33:40

我试图成功地重现您的问题,我发现这是由于当前包azure==4.0.0azure-mgmt-web==0.35.0不支持ftps_state属性(如果您通过pip install azurepip install azure-mgmt-web安装)。您可以参考azure_4.0.0的源代码^{}及其^{}版本来发现它。你知道吗

站点配置_资源.pyazure 4.0.0标签

enter image description here

站点配置_资源.py主分支机构

enter image description here

因此,首先,您需要通过pip卸载azure-sdk-for-python的所有包,如下所示。你知道吗

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

然后,必须从^{}源repo安装包azure-mgmt-web,如下所示。你知道吗

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)

enter image description here

相关问题 更多 >