繁体   English   中英

雪花 sqlalchemy python 无法连接,因为 getaddrinfo 在 company.network 的虚拟机内部失败

[英]Snowflake sqlalchemy python cant connect because of getaddrinfo failed inside virtual machine of company network

我需要读取一些数据并将其写入雪花数据库。 我有凭据,在我的本地电脑上一切正常。 但是在公司的虚拟机中,我正在这样做,我得到了这个我认为这是一个代理问题,但我不知道该怎么做以及如何修复。 在虚拟机上,我可以完美地访问 snowflake url,并且一切都可以在 google chrome 中运行。 但为什么这个请求在 python 中不起作用?? 为什么? 我该如何解决? 请帮忙:(

error message `Traceback (most recent call last):
  File "snowflake\connector\vendored\urllib3\connection.py", line 174, in _new_conn
  File "snowflake\connector\vendored\urllib3\util\connection.py", line 72, in create_connection
  File "socket.py", line 954, in getaddrinfo
socket.gaierror: [Errno 11002] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "snowflake\connector\vendored\urllib3\connectionpool.py", line 703, in urlopen
  File "snowflake\connector\vendored\urllib3\connectionpool.py", line 386, in _make_request
  File "snowflake\connector\vendored\urllib3\connectionpool.py", line 1042, in _validate_conn
  File "snowflake\connector\vendored\urllib3\connection.py", line 358, in connect
  File "snowflake\connector\vendored\urllib3\connection.py", line 186, in _new_conn
snowflake.connector.vendored.urllib3.exceptions.NewConnectionError: <snowflake.connector.vendored.urllib3.connection.HTTPSConnection object at 0x000002073B6C6C10>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "snowflake\connector\vendored\requests\adapters.py", line 489, in send
  File "snowflake\connector\vendored\urllib3\connectionpool.py", line 815, in urlopen
  File "snowflake\connector\vendored\urllib3\connectionpool.py", line 787, in urlopen
  File "snowflake\connector\vendored\urllib3\util\retry.py", line 592, in increment
snowflake.connector.vendored.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='kzhwbsi-gb82213.snowflakecomputing.com', port=443): Max retries exceeded with url: /session/v1/login-request?request_id=d395ab35-5f2a-4fb2-a83b-48458979f2c9&databaseName=project_database&schemaName=project_schema&request_guid=19c8e3a5-33ad-48c2-8124-fc69a1fa2af9 (Caused by NewConnectionError('<snowflake.connector.vendored.urllib3.connection.HTTPSConnection object at 0x000002073B6C6C10>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "snowflake\connector\network.py", line 1018, in _request_exec
  File "snowflake\connector\vendored\requests\sessions.py", line 587, in request
  File "snowflake\connector\vendored\requests\sessions.py", line 701, in send
  File "snowflake\connector\vendored\requests\adapters.py", line 565, in send
snowflake.connector.vendored.requests.exceptions.ConnectionError: HTTPSConnectionPool(host='kzhwbsi-gb82213.snowflakecomputing.com', port=443): Max retries exceeded with url: /session/v1/login-request?request_id=d395ab35-5f2a-4fb2-a83b-48458979f2c9&databaseName=project_database&schemaName=project_schema&request_guid=19c8e3a5-33ad-48c2-8124-fc69a1fa2af9 (Caused by NewConnectionError('<snowflake.connector.vendored.urllib3.connection.HTTPSConnection object at 0x000002073B6C6C10>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "snowflake\connector\connection.py", line 1072, in __authenticate
  File "snowflake\connector\auth.py", line 257, in authenticate
  File "snowflake\connector\network.py", line 704, in _post_request
  File "snowflake\connector\network.py", line 794, in fetch
  File "snowflake\connector\network.py", line 917, in _request_exec_wrapper
  File "snowflake\connector\network.py", line 837, in _request_exec_wrapper
  File "snowflake\connector\network.py", line 1095, in _request_exec
snowflake.connector.errors.OperationalError: 251011: 251011: ConnectionTimeout occurred. Will be handled by authenticator

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "sqlalchemy\engine\base.py", line 3361, in _wrap_pool_connect
  File "sqlalchemy\pool\base.py", line 327, in connect
  File "sqlalchemy\pool\base.py", line 894, in _checkout
  File "sqlalchemy\pool\base.py", line 493, in checkout
  File "sqlalchemy\pool\impl.py", line 146, in _do_get
  File "sqlalchemy\util\langhelpers.py", line 70, in __exit__
  File "sqlalchemy\util\compat.py", line 211, in raise_
  File "sqlalchemy\pool\impl.py", line 143, in _do_get
  File "sqlalchemy\pool\base.py", line 273, in _create_connection
  File "sqlalchemy\pool\base.py", line 388, in __init__
  File "sqlalchemy\pool\base.py", line 691, in __connect
  File "sqlalchemy\util\langhelpers.py", line 70, in __exit__
  File "sqlalchemy\util\compat.py", line 211, in raise_
  File "sqlalchemy\pool\base.py", line 686, in __connect
  File "sqlalchemy\engine\create.py", line 578, in connect
  File "sqlalchemy\engine\default.py", line 598, in connect
  File "snowflake\connector\__init__.py", line 51, in Connect
  File "snowflake\connector\connection.py", line 297, in __init__
  File "snowflake\connector\connection.py", line 550, in connect
  File "snowflake\connector\connection.py", line 789, in __open_connection
  File "snowflake\connector\connection.py", line 1052, in _authenticate
  File "snowflake\connector\connection.py", line 1117, in __authenticate
  File "snowflake\connector\connection.py", line 1094, in __authenticate
  File "snowflake\connector\auth_by_plugin.py", line 117, in handle_timeout
snowflake.connector.errors.OperationalError: 250001: 250001: Could not connect to Snowflake backend after 0 attempt(s).Aborting

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "src\snowflakesqlalchemy.py", line 19, in <module>
  File "sqlalchemy\engine\base.py", line 3315, in connect
  File "sqlalchemy\engine\base.py", line 96, in __init__
  File "sqlalchemy\engine\base.py", line 3394, in raw_connection
  File "sqlalchemy\engine\base.py", line 3364, in _wrap_pool_connect
  File "sqlalchemy\engine\base.py", line 2198, in _handle_dbapi_exception_noconnection
  File "sqlalchemy\util\compat.py", line 211, in raise_
  File "sqlalchemy\engine\base.py", line 3361, in _wrap_pool_connect
  File "sqlalchemy\pool\base.py", line 327, in connect
  File "sqlalchemy\pool\base.py", line 894, in _checkout
  File "sqlalchemy\pool\base.py", line 493, in checkout
  File "sqlalchemy\pool\impl.py", line 146, in _do_get
  File "sqlalchemy\util\langhelpers.py", line 70, in __exit__
  File "sqlalchemy\util\compat.py", line 211, in raise_
  File "sqlalchemy\pool\impl.py", line 143, in _do_get
  File "sqlalchemy\pool\base.py", line 273, in _create_connection
  File "sqlalchemy\pool\base.py", line 388, in __init__
  File "sqlalchemy\pool\base.py", line 691, in __connect
  File "sqlalchemy\util\langhelpers.py", line 70, in __exit__
  File "sqlalchemy\util\compat.py", line 211, in raise_
  File "sqlalchemy\pool\base.py", line 686, in __connect
  File "sqlalchemy\engine\create.py", line 578, in connect
  File "sqlalchemy\engine\default.py", line 598, in connect
  File "snowflake\connector\__init__.py", line 51, in Connect
  File "snowflake\connector\connection.py", line 297, in __init__
  File "snowflake\connector\connection.py", line 550, in connect
  File "snowflake\connector\connection.py", line 789, in __open_connection
  File "snowflake\connector\connection.py", line 1052, in _authenticate
  File "snowflake\connector\connection.py", line 1117, in __authenticate
  File "snowflake\connector\connection.py", line 1094, in __authenticate
  File "snowflake\connector\auth_by_plugin.py", line 117, in handle_timeout
sqlalchemy.exc.OperationalError: (snowflake.connector.errors.OperationalError) 250001: 250001: Could not connect to Snowflake backend after 0 attempt(s).Aborting
(Background on this error at: https://sqlalche.me/e/14/e3q8)
[44952] Failed to execute script 'snowflakesqlalchemy' due to unhandled exception!`


I also printed these logs:
`2023-01-10 11:17:18,250 - MainThread connection.py:275 - __init__() - INFO - Snowflake Connector for Python Version: 2.8.3, Python Version: 3.9.13, Platform: Windows-10-10.0.17763-SP0
2023-01-10 11:17:18,250 - MainThread connection.py:520 - connect() - DEBUG - connect
2023-01-10 11:17:18,250 - MainThread connection.py:810 - __config() - DEBUG - __config
2023-01-10 11:17:18,250 - MainThread connection.py:934 - __config() - INFO - This connection is in OCSP Fail Open Mode. TLS Certificates would be checked for validity and revocation status. Any other Certificate Revocation related exceptions or OCSP Responder failures would be disregarded in favor of connectivity.
2023-01-10 11:17:18,251 - MainThread connection.py:952 - __config() - INFO - Setting use_openssl_only mode to False
2023-01-10 11:17:18,251 - MainThread converter.py:145 - __init__() - DEBUG - use_numpy: False
2023-01-10 11:17:18,251 - MainThread converter_issue23517.py:27 - __init__() - DEBUG - initialized
2023-01-10 11:17:18,251 - MainThread connection.py:713 - __open_connection() - DEBUG - REST API object was created: kzhwbsi-gb82213.snowflakecomputing.com:443
2023-01-10 11:17:18,252 - MainThread auth.py:170 - authenticate() - DEBUG - authenticate
2023-01-10 11:17:18,252 - MainThread auth.py:200 - authenticate() - DEBUG - assertion content: *********
2023-01-10 11:17:18,252 - MainThread auth.py:203 - authenticate() - DEBUG - account=kzhwbsi-gb82213, user=karlpd4c, database=project_database, schema=project_schema, warehouse=None, role=None, request_id=10256208-cea8-4269-a480-820a1c55e4a3
2023-01-10 11:17:18,252 - MainThread auth.py:236 - authenticate() - DEBUG - body['data']: {'CLIENT_APP_ID': 'PythonConnector', 'CLIENT_APP_VERSION': '2.8.3', 'SVN_REVISION': None, 'ACCOUNT_NAME': 'kzhwbsi-gb82213', 'LOGIN_NAME': 'karlpd4c', 'CLIENT_ENVIRONMENT': {'APPLICATION': 'PythonConnector', 'OS': 'Windows', 'OS_VERSION': 'Windows-10-10.0.17763-SP0', 'PYTHON_VERSION': '3.9.13', 'PYTHON_RUNTIME': 'CPython', 'PYTHON_COMPILER': 'MSC v.1929 64 bit (AMD64)', 'OCSP_MODE': 'FAIL_OPEN', 'TRACING': 10, 'LOGIN_TIMEOUT': 120, 'NETWORK_TIMEOUT': None}, 'SESSION_PARAMETERS': {'AUTOCOMMIT': False, 'CLIENT_PREFETCH_THREADS': 4}}
2023-01-10 11:17:18,252 - MainThread auth.py:254 - authenticate() - DEBUG - Timeout set to 120
2023-01-10 11:17:18,253 - MainThread retry.py:351 - from_int() - DEBUG - Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None)
2023-01-10 11:17:18,253 - MainThread retry.py:351 - from_int() - DEBUG - Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None)
2023-01-10 11:17:18,253 - MainThread network.py:1147 - _use_requests_session() - DEBUG - Session status for SessionPool 'kzhwbsi-gb82213.snowflakecomputing.com', SessionPool 1/1 active sessions
2023-01-10 11:17:18,253 - MainThread network.py:827 - _request_exec_wrapper() - DEBUG - remaining request timeout: 120, retry cnt: 1
2023-01-10 11:17:18,254 - MainThread network.py:808 - add_request_guid() - DEBUG - Request guid: 3bcec6fe-8f7d-4c05-9203-626636c975ea
2023-01-10 11:17:18,254 - MainThread network.py:1006 - _request_exec() - DEBUG - socket timeout: 60
2023-01-10 11:17:18,257 - MainThread connectionpool.py:1003 - _new_conn() - DEBUG - Starting new HTTPS connection (1): kzhwbsi-gb82213.snowflakecomputing.com:443
2023-01-10 11:17:19,295 - MainThread retry.py:594 - increment() - DEBUG - Incremented Retry for (url='/session/v1/login-request?request_id=10256208-cea8-4269-a480-820a1c55e4a3&databaseName=project_database&schemaName=project_schema&request_guid=3bcec6fe-8f7d-4c05-9203-626636c975ea'): Retry(total=0, connect=None, read=None, redirect=None, status=None)
2023-01-10 11:17:19,295 - MainThread connectionpool.py:812 - urlopen() - WARNING - Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<snowflake.connector.vendored.urllib3.connection.HTTPSConnection object at 0x00000299937F9A30>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed')': /session/v1/login-request?request_id=10256208-cea8-4269-a480-820a1c55e4a3&databaseName=project_database&schemaName=project_schema&request_guid=3bcec6fe-8f7d-4c05-9203-626636c975ea
2023-01-10 11:17:19,296 - MainThread connectionpool.py:1003 - _new_conn() - DEBUG - Starting new HTTPS connection (2): kzhwbsi-gb82213.snowflakecomputing.com:443
2023-01-10 11:17:19,297 - MainThread network.py:1090 - _request_exec() - DEBUG - Hit a timeout error while logging in. Will be handled by authenticator. Ignore the following. Error stack: HTTPSConnectionPool(host='kzhwbsi-gb82213.snowflakecomputing.com', port=443): Max retries exceeded with url: /session/v1/login-request?request_id=10256208-cea8-4269-a480-820a1c55e4a3&databaseName=project_database&schemaName=project_schema&request_guid=3bcec6fe-8f7d-4c05-9203-626636c975ea (Caused by NewConnectionError('<snowflake.connector.vendored.urllib3.connection.HTTPSConnection object at 0x00000299937F9BE0>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))
Traceback (most recent call last):
  File "snowflake\connector\vendored\urllib3\connection.py", line 174, in _new_conn
  File "snowflake\connector\vendored\urllib3\util\connection.py", line 72, in create_connection
  File "socket.py", line 954, in getaddrinfo
socket.gaierror: [Errno 11002] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "snowflake\connector\vendored\urllib3\connectionpool.py", line 703, in urlopen
  File "snowflake\connector\vendored\urllib3\connectionpool.py", line 386, in _make_request
  File "snowflake\connector\vendored\urllib3\connectionpool.py", line 1042, in _validate_conn
  File "snowflake\connector\vendored\urllib3\connection.py", line 358, in connect
  File "snowflake\connector\vendored\urllib3\connection.py", line 186, in _new_conn
snowflake.connector.vendored.urllib3.exceptions.NewConnectionError: <snowflake.connector.vendored.urllib3.connection.HTTPSConnection object at 0x00000299937F9BE0>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "snowflake\connector\vendored\requests\adapters.py", line 489, in send
  File "snowflake\connector\vendored\urllib3\connectionpool.py", line 815, in urlopen
  File "snowflake\connector\vendored\urllib3\connectionpool.py", line 787, in urlopen
  File "snowflake\connector\vendored\urllib3\util\retry.py", line 592, in increment
snowflake.connector.vendored.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='kzhwbsi-gb82213.snowflakecomputing.com', port=443): Max retries exceeded with url: /session/v1/login-request?request_id=10256208-cea8-4269-a480-820a1c55e4a3&databaseName=project_database&schemaName=project_schema&request_guid=3bcec6fe-8f7d-4c05-9203-626636c975ea (Caused by NewConnectionError('<snowflake.connector.vendored.urllib3.connection.HTTPSConnection object at 0x00000299937F9BE0>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "snowflake\connector\network.py", line 1018, in _request_exec
  File "snowflake\connector\vendored\requests\sessions.py", line 587, in request
  File "snowflake\connector\vendored\requests\sessions.py", line 701, in send
  File "snowflake\connector\vendored\requests\adapters.py", line 565, in send
snowflake.connector.vendored.requests.exceptions.ConnectionError: HTTPSConnectionPool(host='kzhwbsi-gb82213.snowflakecomputing.com', port=443): Max retries exceeded with url: /session/v1/login-request?request_id=10256208-cea8-4269-a480-820a1c55e4a3&databaseName=project_database&schemaName=project_schema&request_guid=3bcec6fe-8f7d-4c05-9203-626636c975ea (Caused by NewConnectionError('<snowflake.connector.vendored.urllib3.connection.HTTPSConnection object at 0x00000299937F9BE0>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))
2023-01-10 11:17:19,305 - MainThread network.py:1152 - _use_requests_session() - DEBUG - Session status for SessionPool 'kzhwbsi-gb82213.snowflakecomputing.com', SessionPool 0/1 active sessions
2023-01-10 11:17:19,305 - MainThread connection.py:1087 - __authenticate() - DEBUG - Operational Error raised at authenticationfor authenticator: AuthByDefault
2023-01-10 11:17:19,305 - MainThread auth_by_plugin.py:114 - handle_timeout() - DEBUG - Default timeout handler invoked for authenticator
2023-01-10 11:17:19,305 - MainThread auth_by_plugin.py:123 - handle_timeout() - DEBUG - Hit connection timeout, attempt number 0. Will retry in a bit...
2023-01-10 11:17:19,305 - MainThread auth_by_plugin.py:56 - next_sleep_duration() - DEBUG - Sleeping for 2 seconds
2023-01-10 11:17:21,306 - MainThread auth.py:170 - authenticate() - DEBUG - authenticate
2023-01-10 11:17:21,306 - MainThread auth.py:200 - authenticate() - DEBUG - assertion content: *********
2023-01-10 11:17:21,306 - MainThread auth.py:203 - authenticate() - DEBUG - account=kzhwbsi-gb82213, user=karlpd4c, database=project_database, schema=project_schema, warehouse=None, role=None, request_id=f8210470-5260-46c4-b7a5-1458f5dc318a
2023-01-10 11:17:21,306 - MainThread auth.py:236 - authenticate() - DEBUG - body['data']: {'CLIENT_APP_ID': 'PythonConnector', 'CLIENT_APP_VERSION': '2.8.3', 'SVN_REVISION': None, 'ACCOUNT_NAME': 'kzhwbsi-gb82213', 'LOGIN_NAME': 'karlpd4c', 'CLIENT_ENVIRONMENT': {'APPLICATION': 'PythonConnector', 'OS': 'Windows', 'OS_VERSION': 'Windows-10-10.0.17763-SP0', 'PYTHON_VERSION': '3.9.13', 'PYTHON_RUNTIME': 'CPython', 'PYTHON_COMPILER': 'MSC v.1929 64 bit (AMD64)', 'OCSP_MODE': 'FAIL_OPEN', 'TRACING': 10, 'LOGIN_TIMEOUT': 120, 'NETWORK_TIMEOUT': None}, 'SESSION_PARAMETERS': {'AUTOCOMMIT': False, 'CLIENT_PREFETCH_THREADS': 4}}
2023-01-10 11:17:21,307 - MainThread auth.py:254 - authenticate() - DEBUG - Timeout set to 120
2023-01-10 11:17:21,307 - MainThread network.py:1147 - _use_requests_session() - DEBUG - Session status for SessionPool 'kzhwbsi-gb82213.snowflakecomputing.com', SessionPool 1/1 active sessions
2023-01-10 11:17:21,307 - MainThread network.py:827 - _request_exec_wrapper() - DEBUG - remaining request timeout: 120, retry cnt: 1
2023-01-10 11:17:21,307 - MainThread network.py:808 - add_request_guid() - DEBUG - Request guid: dbe010e1-6776-46ed-bc5a-9979d617bee4
2023-01-10 11:17:21,307 - MainThread network.py:1006 - _request_exec() - DEBUG - socket timeout: 60
2023-01-10 11:17:21,311 - MainThread connectionpool.py:1003 - _new_conn() - DEBUG - Starting new HTTPS connection (3): kzhwbsi-gb82213.snowflakecomputing.com:443
2023-01-10 11:17:21,312 - MainThread retry.py:594 - increment() - DEBUG - Incremented Retry for (url='/session/v1/login-request?request_id=f8210470-5260-46c4-b7a5-1458f5dc318a&databaseName=project_database&schemaName=project_schema&request_guid=dbe010e1-6776-46ed-bc5a-9979d617bee4'): Retry(total=0, connect=None, read=None, redirect=None, status=None)
2023-01-10 11:17:21,312 - MainThread connectionpool.py:812 - urlopen() - WARNING - Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<snowflake.connector.vendored.urllib3.connection.HTTPSConnection object at 0x000002999382B790>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed')': /session/v1/login-request?request_id=f8210470-5260-46c4-b7a5-1458f5dc318a&databaseName=project_database&schemaName=project_schema&request_guid=dbe010e1-6776-46ed-bc5a-9979d617bee4
2023-01-10 11:17:21,312 - MainThread connectionpool.py:1003 - _new_conn() - DEBUG - Starting new HTTPS connection (4): kzhwbsi-gb82213.snowflakecomputing.com:443
2023-01-10 11:17:21,314 - MainThread network.py:1090 - _request_exec() - DEBUG - Hit a timeout error while logging in. Will be handled by authenticator. Ignore the following. Error stack: HTTPSConnectionPool(host='kzhwbsi-gb82213.snowflakecomputing.com', port=443): Max retries exceeded with url: /session/v1/login-request?request_id=f8210470-5260-46c4-b7a5-1458f5dc318a&databaseName=project_database&schemaName=project_schema&request_guid=dbe010e1-6776-46ed-bc5a-9979d617bee4 (Caused by NewConnectionError('<snowflake.connector.vendored.urllib3.connection.HTTPSConnection object at 0x000002999382BA00>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))
Traceback (most recent call last):
  File "snowflake\connector\vendored\urllib3\connection.py", line 174, in _new_conn
  File "snowflake\connector\vendored\urllib3\util\connection.py", line 72, in create_connection
  File "socket.py", line 954, in getaddrinfo
socket.gaierror: [Errno 11002] getaddrinfo failed

During handling of the above exception, another exception occurred:

...

这是我的 python 代码:

#!/usr/bin/env python
from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine
import pandas as pd
import logging
import os
engine = create_engine('snowflake://user:password@myaccount(e.g.asdfhjk-jh45567)/project_database/project_schema')
os.environ['NO_PROXY'] = 'snowflakecomputing.com'
path = input('logpath:\n')
for logger_name in ['snowflake','botocore']:
    logger = logging.getLogger(logger_name)
    logger.setLevel(logging.DEBUG)
    ch = logging.FileHandler(path+'python_connector.log')
    ch.setLevel(logging.DEBUG)
    ch.setFormatter(logging.Formatter('%(asctime)s - %(threadName)s %(filename)s:%(lineno)d - %(funcName)s() - %(levelname)s - %(message)s'))
    logger.addHandler(ch)
try:
    
    connection = engine.connect()
    sql = "SELECT * FROM project_comments"
    df = pd.read_sql_query(sql,connection)
    print(df)
    df.to_csv("./snowflakedata.csv",index=False)
finally:

    engine.dispose()
connection.close()

除了使用 sqlalchemy,我还尝试了雪花连接器:

import pandas as pd
import snowflake.connector
import sys
import os
us = input("user: \n")
pw = input("password: \n")
acc = input("account: \n")
cnn = snowflake.connector.connect(
    user=us,
    password=pw,
    account=acc,
    
)
cs = cnn.cursor()
wh = input("warehouse: \n")
db = input("database: \n")
schema = input("schema: \n")
table = input("table: \n")
path = input("output directory: \n").replace("\\", "/")
try:
    sql = "USE WAREHOUSE " + wh
    cs.execute(sql)
    sql = "USE DATABASE "+ db
    cs.execute(sql)
    sql = "USE SCHEMA " + schema
    cs.execute(sql)
    sql = "SELECT * FROM " + table
    df = pd.read_sql_query(sql,cnn)
    print(df)
    df.to_csv(path + "snowflakedata.csv",index=False)
    input("snowflake has been read, press any key to close")
finally:
    cs.close()
cnn.close()

出现同样的问题。 在本地电脑上它工作正常,在内部部署的虚拟机上。网络它不起作用。 我试图通过以下方式停用 windows 中的代理:

set NO_PROXY=snowflakecomputing.com

我需要雪花数据库的 ip 吗? 我如何得到它? 是不是sqlalchemy里面的dns配置有问题? 我如何解决它? 我需要另一个连接器或数据库引擎吗?

我找到了答案:如果你在合作代理后面,你需要在环境变量中将代理配置为新变量,然后添加这两个:

HTTP_PROXY http://companyuser:companypw@proxy.companydomain.companyname.com:8080 和

HTTPS_PROXY http://companyuser:companypw@proxy.companydomain.companyname.com:8080

.然后您还需要在应用程序级别配置那些 http 和 https 代理,这意味着在您的 python 程序开始时:

os.environ["http_proxy"] = "http://companyuser:companypw@proxy.companydomain.companyname.com:8080"
os.environ["https_proxy"] ="http://companyuser:companypw@proxy.companydomain.companyname.com:8080"

在我的例子中,companyuser 是我的 windows 机器上的用户。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM