Python does work OK in SQL 2019: EXEC sp_execute_external_script @language =N'HPython2', @script=N' import sys; print("\n".join(sys.path)) ' GO gives: STDOUT message(s) from external script: C:/Program Files/Microsoft SQL Server/MSSQL15.MSSQLSERVER/MSSQL/ExternalLibraries/1/65539/1 C:\Program Files\Python\Python310\python310.zip C:\Program Files\Python\Python310\DLLs C:\Program Files\Python\Python310\lib C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Binn C:\Program Files\Python\Python310 C:\Program Files\Python\Python310\lib\site-packages C:\Program Files\Python\Python310\lib\site-packages\win32 C:\Program Files\Python\Python310\lib\site-packages\win32\lib C:\Program Files\Python\Python310\lib\site-packages\Pythonwin Connections do work in Python 3.10: import requests r = requests.get("https://www.google.com") r.status_code print(r.status_code) print("End") The same does not work as external script in SQL 2019: EXEC sp_execute_external_script @language = N'HPython2', @script = N' import requests r = requests.get("https://www.google.com") r.status_code print(r.status_code) print("End") ' it gives: Msg 39004, Level 16, State 20, Line 5 A 'HPython2' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004. STDOUT message(s) from external script: 2025-09-10 02:46:08.94 Error: Python error: <class 'requests.exceptions.ConnectionError'>: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000214FD50E1D0>: Failed to establish a new connection: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions')): File "", line 3, in File "C:\Program Files\Python\Python310\lib\site-packages\requests\api.py", line 73, in get return request("get", url, params=params, **kwargs) File "C:\Program Files\Python\Python310\lib\site-packages\requests\api.py", line 59, in request return session.request(method=method, url=url, **kwargs) File "C:\Program Files\Python\Python310\lib\site-packages\requests\sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) File "C:\Program Files\Python\Python310\lib\site-packages\requests\sessions.py", line 703, in send r STDOUT message(s) from external script: = adapter.send(request, **kwargs) File "C:\Program Files\Python\Python310\lib\site-packages\requests\adapters.py", line 700, in send raise ConnectionError(e, request=request) Similar with the R extension, it works in R but gives a connection error with sp_execute_external_script It also fails with firewall off! But it used to work a while ago with firewall on. I haven't a clue what has changed. Looking at this for more than a day, while at the same time working around it by doing some steps manually. Firewall On and Off enabling Ports 1433 and 443 in firewall same script outside SQL (SSMS) Different versions of Python and R All with same results! Continue reading...