I am trying to get some data from a website in SQL using Python(SQL2017 - machine learning services). I have setup SQL2017, and ML services for python and it is working fine,for an example, following code is working
exec sp_execute_external_script
@language =N'Python',
@script = N'
import pandas as pd
print(" This is test")'
Though, when I am trying to get anything from web, using following basic commands, I am getting error- I am trying this from my home internet as well as corporate environment: also, same get method works from my python IDE
EXEC sp_execute_external_script
@language =N'Python',
@script=N'
import requests
out = requests.request("GET","http://example.com")'
Error Code:
Msg 39004, Level 16, State 20, Line 0
A 'Python' script error occurred during execution of
'sp_execute_external_script' with HRESULT 0x80004004.
Msg 39019, Level 16, State 2, Line 0
An external script error occurred:
Error in execution. Check the output for more information.
Traceback (most recent call last):
File "C:\Program Files\Microsoft SQL
Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-
packages\requests\packages\urllib3\connection.py", line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "C:\Program Files\Microsoft SQL
Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-
packages\requests\packages\urllib3\util\connection.py", line 83, in
create_connection
raise err
File "C:\Program Files\Microsoft SQL
Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-
packages\requests\packages\urllib3\util\connection.py", line 73, in
create_connection
sock.connect(sa)
OSError: [WinError 10013] An attempt was made to access a socket in a way
forbidden by its access permissions
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
Msg 39019, Level 16, State 2, Line 0
An external script error occurred:
File "C:\Program Files\Microsoft SQL
Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-
packages\requests\packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Program Files\Microsoft SQL
Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-
packages\requests\packages\urllib3\connectionpool.py", line 356, in
_make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Program Files\Microsoft SQL
Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\http\client.py", line 1106,
in request
self._send_request(method, url, body, headers)
File "C:\Program Files\Microsoft SQL
Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\http\client.py", line 1151,
in _send_request
self.endheaders(body)
File "C:\Program Files\Microsoft SQL
Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\http\client.py", line 1102,
in endheaders
self._send_output(message_body)
Can anyone please help. Regards
I also had the same issue. David Browne has said the following to do and it worked for me:
Open the Windows Firewall and look for a rule called "Block network access for R local user accounts in SQL Server instance MSSQLSERVER" (assuming you have a default instance). This Firewall rule blocks network access from SQL Server external scripts. You can disable the rule if you want to allow network access.
Please try disabling the above rule.
User contributions licensed under CC BY-SA 3.0