1

I have written some Python code for an azure function and everything works fine when I execute it locally in VS code through Azure Functions Core Tools. The code calls a REST API.

When I deploy it to azure it fails with the following error, any idea on how to debug this?

Result: Failure Exception: SSLError: HTTPSConnectionPool(host='api.myurl.net', port=443): Max retries exceeded with url: /payments/123456 (Caused by SSLError(SSLError(1, '[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:1125)'))) Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 355, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 542, in __run_sync_func return func(**params) File "/home/site/wwwroot/HttpTrigger1/__init__.py", line 15, in main status, body, headers = client.get('/payments/234368493',raw=True) File "/home/site/wwwroot/.python_packages/lib/site-packages/quickpay_api_client/api.py", line 80, in perform response = self.fulfill(method, url, File "/home/site/wwwroot/.python_packages/lib/site-packages/quickpay_api_client/api.py", line 44, in fulfill return getattr(self.session, method)(*args, **kwargs) File "/home/site/wwwroot/.python_packages/lib/site-packages/requests/sessions.py", line 555, in get return self.request('GET', url, **kwargs) File "/home/site/wwwroot/.python_packages/lib/site-packages/requests/sessions.py", line 542, in request resp = self.send(prep, **send_kwargs) File "/home/site/wwwroot/.python_packages/lib/site-packages/requests/sessions.py", line 655, in send r = adapter.send(request, **kwargs) File "/home/site/wwwroot/.python_packages/lib/site-packages/requests/adapters.py", line 514, in send raise SSLError(e, request=request)

2 Answers2

1

The problem was in the code of one of the installed python modules. The module used the poolmanager and I suspect the problem was in that. I rewrote the code and now it's working.

0

Your problem is caused by your certificate is not trusted, you can try to use the following ways to solve it.

1. You can refer to SSLError (bad handshake) when using Azure CLI to get the trusted certificate, you can get the trusted certificate by the URL mentioned by the error message in a browser.

2. You can try to disable certificate verification, please refer to SSL handshake error with some Azure CLI commands:

set ADAL_PYTHON_SSL_NO_VERIFY=1
set AZURE_CLI_DISABLE_CONNECTION_VERIFICATION=1
Frank Borzage
  • 6,292
  • 1
  • 6
  • 19
  • So just for my understanding. My Python code makes a REST call to https://api.quickpay,net but the certificate is not trusted by my Azure Function? That makes no sense since its not a selfsigned certrificate. – Lars Hædersdal Mar 03 '21 at 09:11
  • How can I set these environment variable upon the start of my Azure Function made in Python? I have a company proxy that I cannot disable. When the Azure Function Host starts on my local laptop I need a way to run these 2 commands for the Host environment but I don't know how. – Oliver Nilsen Sep 19 '22 at 12:40