我正在尝试直接在雪花中调用rest API。为此,我尝试使用 Python 存储过程。像往常一样,我尝试调用 requests.get() 方法。但不幸的是Snowflake目前不支持建立http连接。根据我需要从 Snowflake 执行外部应用程序。使用雪花查询窗口执行 shell 脚本的任何选项。。我需要使用外部函数。但我无法访问aws帐户,并且由于各种原因不会提供。
任何人都可以建议任何替代方法吗?
例如,我们正在使用公共 REST API
如果不可能,您仍然可以建议一些不使用任何外部函数的最近的解决方案。
滑雪场代码是:
import snowflake.snowpark as snowpark
from snowflake.snowpark.functions import col, avg, as_integer
import requests
def main(session: snowpark.Session):
r = request.get('https://api.publicapis.org/entries')
return r
Traceback (most recent call last):
File "urllib3/connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "urllib3/util/connection.py", line 72, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/lib/python_udf/7514b8b71a5770c388d7c6f6030134a2a250933021f5c5a0e176ded90a60847a/lib/python3.8/socket.py", line 918, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "urllib3/connectionpool.py", line 714, in urlopen
httplib_response = self._make_request(
File "urllib3/connectionpool.py", line 403, in _make_request
self._validate_conn(conn)
File "urllib3/connectionpool.py", line 1053, in _validate_conn
conn.connect()
File "urllib3/connection.py", line 363, in connect
self.sock = conn = self._new_conn()
File "urllib3/connection.py", line 186, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0xffff728c2c10>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "requests/adapters.py", line 486, in send
resp = conn.urlopen(
File "urllib3/connectionpool.py", line 798, in urlopen
retries = retries.increment(
File "urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.publicapis.org', port=443): Max retries exceeded with url: /entries (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0xffff728c2c10>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
Worksheet, line 5, in main
File "requests/api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "requests/sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "requests/sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "requests/adapters.py", line 519, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.publicapis.org', port=443): Max retries exceeded with url: /entries (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0xffff728c2c10>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
外部网络访问目前在 AWS 中处于公共预览版,您可以对 REST API 进行外部调用。