-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
got HTTP 400 error when calling WebSiteManagementClient.web_apps.install_site_extension() #2828
Comments
Can you capture the error response on the wire and see whether there is any error detail inside? |
msrestazure.azure_exceptions.CloudError: 400 Client Error: Bad Request for url: https://management.azure.com/subscriptions/_mysubsciptionId_/resourceGroups/agri-api-dev-appservice/providers/Microsoft.Web/sites/agriOUSDevAUE2/siteextensions/Microsoft.ApplicationInsights.AzureWebSites?api-version=2016-08-01 Below is a copy of my code. I can confirm that the Azure WebApp does get provisioned successfully. It is the provision of extension, which failed. I tried to capture error via AzureException, however, it doesn't seem logging anything which is useful for debugging. import os.path
import json
import sys
from azure.mgmt.web import WebSiteManagementClient
from azure.common.credentials import ServicePrincipalCredentials
from azure.common import AzureException
parameters_common = "./azure/config/parameters-common.json"
with open(parameters_common, 'r') as parameters_common_fd:
arm_parameters_common = json.load(parameters_common_fd)
parameters_appService_plan = "./azure/config/output-agri-api-dev-appservice.json"
with open(parameters_appService_plan, 'r') as parameters_appService_plan_fd:
arm_parameters_appService_plan = json.load(parameters_appService_plan_fd)
my_subscription_id = arm_parameters_common['SubscriptionId']
my_azure_client_id = arm_parameters_common['ClientId']
my_azure_secret_id = arm_parameters_common['SecretId']
my_azure_tenant_id = arm_parameters_common['TenantId']
my_location = arm_parameters_appService_plan['location']
my_rg_id = arm_parameters_appService_plan['resource_group_id']
my_rg_name = my_rg_id.split('/')[-1]
my_service_plan_id = arm_parameters_appService_plan['appServicePlanName']
json_output = {} #Initialize a dictory container for JSON data processing
def deploy_app_service():
print("\nDeploying App Service To Resource Group\n")
AzureServicePrincipalcredentials = ServicePrincipalCredentials(
client_id = my_azure_client_id,
secret = my_azure_secret_id,
tenant = my_azure_tenant_id
)
web_client = WebSiteManagementClient(AzureServicePrincipalcredentials, my_subscription_id)
site_async_operation = web_client.web_apps.create_or_update(
my_rg_name,
"agriOUSDevAUE2",
{
'location': my_location,
'server_farm_id': my_service_plan_id,
'reserved': False,
'enabled': True,
'kind': 'app',
'site_config': {
"scmType": "LocalGit"
}
}
)
# my_site_extension = web_client.web_apps.list_site_extensions(
# my_rg_name,
# 'agriOUSDevAUE'
# )
# for each_site in my_site_extension:
# print(each_site)
try:
my_site_extension = web_client.web_apps.install_site_extension(
my_rg_name,
"agriOUSDevAUE2",
"Microsoft.ApplicationInsights.AzureWebSites"
)
except AzureException as e:
print(e.response)
if __name__ == "__main__":
deploy_app_service() |
Hi @APAC-DevOps web_client.config.enable_http_logger=True and then use "logging" to show DEBUG logs. You will the HTTP answer with all details. |
I'd try running this without |
I added the line "web_client.config.enable_http_logger=True" to my code, and set my python code's logging level to "debug", below is what I got (I commented out subscription ID from the output, but apart from that, all of the output from my Mac computer is displayed below) WARNING:msrest.service_client:Accept header absent and forced to application/json During handling of the above exception, another exception occurred: Traceback (most recent call last): |
Indeed, I don't see any troubling thing here :(. And the error from the server is 400 and has no body to explain the trouble :( 400 usually means the resource does not exist. @yugangw-msft I see that @APAC-DevOps could you add after your while True:
try:
web_client.web_apps.get(
my_rg_name,
"agriOUSDevAUE2"
)
break
except Exception as err:
print("Assuming WebApp is not ready")
time.sleep(10) And see:
Thanks, |
Maybe @panchagnula can help |
Did not read entire thread completely but i see from the ARM template you have "phpVersion": "off", |
@panchagnula With WebApp siteextensions, if I write define my ARM resource as embedded resource as below, the provision of the extension "Microsoft.ApplicationInsights.AzureWebSites" does fail occasionally. "resources": [
however, since I define resources by using "dependson" as below, my WebApp provision works fine. To me, it is something bizarre, and should not have happened, but it did.
@lmazuel As I have got my pipeline working fine with ARM templates, and the issue with python code seems too difficult to be debugged, so I am OK to let it pass for the time being. |
Up to this point, I would say this seems likely to be a bug in Azure Rest Api. Apart from Python SDK, I also tried the rest api call at: https://docs.microsoft.com/en-us/rest/api/appservice/webapps/webapps_installsiteextension Eventually, I found a sample on Internet which used kudu api in powershell code excerpt for enabling extension on Azure WebApp. I did reading, and probing, and here comes my python code for enabling extensions of Azure WebApp. add asp net core extension to OUS WebApp
I found it is very difficult to find python code sample for AWS SDK on Internet. Can you tell me if there is any good website which can give me some guide when I went into deadend (apart from github). |
Is this issue still valid in azure-mgmt-web 6.1.0? |
Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you! |
I have a python function which does Azure Web App service deployment along with the extension AspNetCore. If I commented out the lines for installing site extension, my script ran happily; however, with the lines for AspNet Core extension installation, my script can not run successfully.
If I do the manual installation via Azure Portal, then, I can complete the extension installation successfully. I wrote ARM templates with site and extension provision, again, my code runs happily. But calling WebSiteManagementClient.web_apps.install_site_extension() like below doesn't work, and I got
msrestazure.azure_exceptions.CloudError: 400 Client Error: Bad Request for url: https://management.azure.com/subscriptions/XXXXX(sensitive info)/siteextensions/AspNetCoreRuntime?api-version=2016-08-01
can you take a look and see if I missed anything here?
ARM Template
{
"apiVersion": "2015-08-01",
"name": "[parameters('siteName')]",
"type": "Microsoft.Web/sites",
"location": "[parameters('location')]",
"properties": {
"name": "[parameters('siteName')]",
"serverFarmId": "[parameters('appServicePlanId')]"
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "web",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
],
"properties": {
"phpVersion": "off",
"netFrameworkVersion": "v4.0",
"webSocketsEnabled": true,
"requestTracingEnabled": true,
"httpLoggingEnabled": true,
"logsDirectorySizeLimit": 40,
"detailedErrorLoggingEnabled": true,
"scmType": "LocalGit"
}
},
Python Code
def deploy_app_service():
print("\nDeploying App Service To Resource Group\n")
AzureServicePrincipalcredentials = ServicePrincipalCredentials(
client_id = my_azure_client_id,
secret = my_azure_secret_id,
tenant = my_azure_tenant_id
)
web_client = WebSiteManagementClient(AzureServicePrincipalcredentials, my_subscription_id)
install site extension
The text was updated successfully, but these errors were encountered: