I’m deploying a Flask app to Azure, and I’m running into a RecursionError: maximum recursion depth exceeded error that only occurs when the app is deployed. The same code works perfectly fine locally.
Error Message:
"maximum recursion depth exceeded",
"Traceback (most recent call last):n File "/tmp/8dcbee2adc4d770/app.py", line 80, in indexn response = http.request(n File "/agents/python/urllib3/_request_methods.py", line 144, in requestn return self.request_encode_body(n File "/agents/python/urllib3/_request_methods.py", line 279, in request_encode_bodyn return self.urlopen(method, url, **extra_kw)n File "/agents/python/urllib3/poolmanager.py", line 444, in urlopenn response = conn.urlopen(method, u.request_uri, **kw)n File "/agents/python/wrapt/wrappers.py", line 669, in __call__n return self._self_wrapper(self.__wrapped__, self._self_instance,n File "/agents/python/opentelemetry/instrumentation/urllib3/__init__.py", line 251, in instrumented_urlopenn response = wrapped(*args, **kwargs)n File "/agents/python/urllib3/connectionpool.py", line 793, in urlopenn response = self._make_request(n File "/agents/python/urllib3/connectionpool.py", line 467, in _make_requestn self._validate_conn(conn)n File "/agents/python/urllib3/connectionpool.py", line 1099, in _validate_connn conn.connect()n File "/agents/python/urllib3/connection.py", line 653, in connectn sock_and_verified = _ssl_wrap_socket_and_match_hostname(n File "/agents/python/urllib3/connection.py", line 759, in _ssl_wrap_socket_and_match_hostnamen context = create_urllib3_context(n File "/agents/python/urllib3/util/ssl_.py", line 290, in create_urllib3_contextn context.minimum_version = TLSVersion.TLSv1_2n File "/opt/python/3.10.14/lib/python3.10/ssl.py", line 604, in minimum_versionn super(SSLContext, SSLContext).minimum_version.__set__(self, value)n File "/opt/python/3.10.14/lib/python3.10/ssl.py", line 604, in minimum_versionn super(SSLContext, SSLContext).minimum_version.__set__(self, value)n File "/opt/python/3.10.14/lib/python3.10/ssl.py", line 604, in minimum_versionn super(SSLContext, SSLContext).minimum_version.__set__(self, value)n [Previous line repeated 476 more times]nRecursionError: maximum recursion depth exceededn"
Here’s the relevant part of my code:
http = urllib3.PoolManager()
encoded_payload = urllib.parse.urlencode(payload).encode('utf-8')
response = http.request('POST', url, body=encoded_payload, headers=headers)
response_data = json.loads(response.data.decode('utf-8'))
Deployment Configuration:
I’m using Gunicorn to deploy the app on Azure. Here’s my startup configuration:
Startup command in Azure:
gunicorn --bind=0.0.0.0:8000 --timeout 600 --worker-class gevent --preload app:app
I also have this startup.txt:
gunicorn --bind=0.0.0.0:8000 --timeout 600 --worker-class gevent app:app
When I remove the startup command in Azure, the request is successful, but other parts of the code that involve WebSockets stop working.
The error doesn’t occur locally, only when the app is deployed on Azure. And I think the recursion error seems to be related to SSL context creation and handling, but I’m unsure why this would cause a recursion loop.
ishansheth31 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1