RecursionError: maximum recursion depth exceeded when deploying Flask app with Gunicorn on Azure

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.

New contributor

ishansheth31 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật