
[英]Error when trying to fit the model in Colab but works fine in Jupyter notebook
[英]Attribute Error in snowflake.connector cursor() only when using MS VS Code but works fine in Jupyter Notebook
我有一个代码,我想将它从 jupyter notebook 转换为脚本。 它本质上是从我们的 Snowflake 湖中提取数据并进行一些操作。 这是它在 Jupyter Notebook 中的样子:
conn = snowflake.connector.connect(<connection parameters>)
ib_cursor = conn.cursor()
try:
ib_cursor.execute(ib_sql.read(), params)
ib_rows = ib_cursor.fetchall()
这适用于 Jupyter 代码。 数据加载到ib_rows
变量中就好了。
在 MS Visual Studio 代码脚本中,我只是为了我的目的创建了一个 class。 这是它的大致样子:
class snowflk_sql:
def __init__(self, conn_parameters):
self.connection_params = conn_parameters
self.connection_obj = snowflake.connector.connect(user= self.connection_params['user'],
account= self.connection_params['account'],
role= self.connection_params['role'],
database= self.connection_params['database'],
schema = self.connection_params['schema'],
authenticator="externalbrowser",
autocommit=True)
def sql_execute(self,parameter):
ib_cursor = self.connection_obj.cursor()
so_cursor = self.connection_obj.cusror()
#.......<some logic>......
try:
# sql being executed using parameters in the parameter file
ib_cursor.execute(ib_sql.read(), parameter)
ib_rows = ib_cursor.fetchall()
# rest of the code
def main(connection_param,parameter):
# creating the snowflake connection
snowflk_sql_obj = snowflk_sql(connection_param)
# executing the sql
ib_df,so_df = snowflk_sql_obj.sql_execute(q_parameter)
但是为此,我不断收到以下错误
AttributeError: 'SnowflakeConnection' object has no attribute 'cusror'
根据我的搜索,有一些关于sqlalchemy
的内容,但是如果我只是获取行然后转换为 dataframe 怎么办。我无法理解为什么如果它在 Jupyter 中有效,它在我的脚本中也不起作用。
您的代码有一个拼写错误(cusror):
def sql_execute(self,parameter):
ib_cursor = self.connection_obj.cursor()
so_cursor = self.connection_obj.cusror() # typo
应该
def sql_execute(self,parameter):
ib_cursor = self.connection_obj.cursor()
so_cursor = self.connection_obj.cursor() # corrected
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.