HTTP Timeout in Azure Python Web App

2024-05-08T14:36:11.95+00:00

I'm developying a Flask Web App and i need to use the following code:

from nba_api.stats.library.parameters import PerMode36, LeagueIDNullable
import requests

response = requests.get(
				url="https://stats.nba.com/stats/playercareerstats",
				params={
                	"PlayerID": '203999',
                    "PerMode": PerMode36.default,
                    "LeagueID": LeagueIDNullable.default,
                },
                headers={
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0",
                    "Referer": "https://stats.nba.com/"
                },
                timeout=30)

This HTTP request works correctly on my local app but in the same code inside an Azure Web App it generats the a timeout error:

requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='stats.nba.com', port=443): Read timed out. (read timeout=30)

Even increasing the timeout, the result remains same.

nba_api is available in pip.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,901 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 26,626 Reputation points Microsoft Employee
    2024-05-09T13:20:59.4733333+00:00

    @Nicola Paoluzzi - nicola.paoluzzi@studio.unibo.it ,

    I understand you have mentioned it works locally, are you leveraging any proxy? Kindly ensure that the client machine has appropriate network connectivity to the Kudu site of the target deployment.

    To isolate the issue, please validate using Kudu Bash https://<site-name>.scm.azurewebsites.net/DebugConsole and dig.

    As a quick steps, you may scale-up your App Service Plan and test: Best Practices for Azure App Service

    If you haven't done, you may leverage App Service diagnostics from Azure Portal> Navigate to your App Service app in the Azure Portal.

    In the left navigation, click on Diagnose and solve problems - Review - “Configuration and Management” options. To begin with, you may leverage App Service diagnostics from Azure Portal> Navigate to your App Service app in the Azure Portal. 

    Also, review Enable and review logs to fetch more details about the error.

    Please let us know, I'll follow-up with you further.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.