Reading from excel to printing on postgresql using python. I get error

Here is the code that I have written and I can not understand why I get the issues below the code. Does anybody have any idea? I am a new coder, and this is what my boss gave me to try me. I would accept any comments because I am trying to improve as much as I can. Also I am doing it on VS Code

The code:

from sqlalchemy import create_engine

from sqlalchemy.engine import URL

import pypyodbc

import pandas as pd

SERVER_NAME = ”

DATABASE_NAME = ”

TABLE_NAME = ”

excel_file = “C:JordiBook2.xlsx”

connection_string = f”””

DRIVER={{SQL Server}};
SERVER={"AdariaGroup"};
DATABASE={"postgres"};
Trusted_Connection=yes;

“””
connection_url = URL.create(‘mssql+pyodbc’, query={‘odbc_connect’: connection_string})

enigne = create_engine(connection_url, module=pypyodbc)

excel_file = pd.read_excel(excel_file, sheet_name=None)

for sheet_name, df_data in excel_file.items():

print(f'Loading worksheet {sheet_name}...')

df_data.to_sql(TABLE_NAME, enigne, if_exists='append', index=False)

”—————————————————————————————”

The error:

PS C:UsersantoaDesktopJordi PY TO SQL> & “C:/Program Files/Python312/python.exe” “c:/Users/antoa/Desktop/Jordi PY TO SQL/JordiSQLTOPy.py”
c:UsersantoaDesktopJordi PY TO SQLJordiSQLTOPy.py:10: SyntaxWarning: invalid escape sequence ‘J’
excel_file = “C:JordiBook2.xlsx”
Loading worksheet Sheet1…
Traceback (most recent call last):
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyenginebase.py”, line 146, in init
self._dbapi_connection = engine.raw_connection()
^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyenginebase.py”, line 3300, in raw_connection
return self.pool.connect()
^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolbase.py”, line 449, in connect
return _ConnectionFairy._checkout(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolbase.py”, line 1263, in _checkout
fairy = _ConnectionRecord.checkout(pool)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolbase.py”, line 712, in checkout
rec = pool._do_get()
^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolimpl.py”, line 179, in _do_get
with util.safe_reraise():
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyutillanghelpers.py”, line 146, in exit
raise exc_value.with_traceback(exc_tb)
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolimpl.py”, line 177, in _do_get
return self._create_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolbase.py”, line 390, in _create_connection
return _ConnectionRecord(self)
^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolbase.py”, line 674, in init
self.__connect()
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolbase.py”, line 900, in __connect
with util.safe_reraise():
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyutillanghelpers.py”, line 146, in exit
raise exc_value.with_traceback(exc_tb)
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolbase.py”, line 896, in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyenginecreate.py”, line 643, in connect
return dialect.connect(*cargs, **cparams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyenginedefault.py”, line 620, in connect
return self.loaded_dbapi.connect(*cargs, **cparams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespypyodbc.py”, line 2454, in init
self.connect(connectString, autocommit, ansi, timeout, unicode_results, readonly)
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespypyodbc.py”, line 2507, in connect
check_success(self, ret)
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespypyodbc.py”, line 1009, in check_success
ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h, ret, ODBC_obj.ansi)
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespypyodbc.py”, line 987, in ctrl_err
raise DatabaseError(state,err_text)
pypyodbc.DatabaseError: (‘08001’, ‘[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.’)

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

Traceback (most recent call last):
File “c:UsersantoaDesktopJordi PY TO SQLJordiSQLTOPy.py”, line 29, in
df_data.to_sql(TABLE_NAME, enigne, if_exists=’append’, index=False)
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespandasutil_decorators.py”, line 333, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespandascoregeneric.py”, line 3087, in to_sql
return sql.to_sql(
^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespandasiosql.py”, line 841, in to_sql
with pandasSQL_builder(con, schema=schema, need_transaction=True) as pandas_sql:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespandasiosql.py”, line 906, in pandasSQL_builder
return SQLDatabase(con, schema, need_transaction)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespandasiosql.py”,

line 1636, in init

con = self.exit_stack.enter_context(con.connect())
                                    ^^^^^^^^^^^^^

File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyenginebase.py”, line 3276, in connect
return self._connection_cls(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyenginebase.py”, line 148, in init
Connection._handle_dbapi_exception_noconnection(
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyenginebase.py”, line 2440, in _handle_dbapi_exception_noconnection
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyenginebase.py”, line 146, in init
self._dbapi_connection = engine.raw_connection()
^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyenginebase.py”, line 3300, in raw_connection
return self.pool.connect()
^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolbase.py”, line 449, in connect
return _ConnectionFairy._checkout(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolbase.py”, line 1263, in _checkout
fairy = _ConnectionRecord.checkout(pool)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolbase.py”, line 712, in checkout
rec = pool._do_get()
^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolimpl.py”, line 179, in _do_get
with util.safe_reraise():
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyutillanghelpers.py”, line 146, in exit
raise exc_value.with_traceback(exc_tb)
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolimpl.py”, line 177, in _do_get
return self._create_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolbase.py”, line 390, in _create_connection
return _ConnectionRecord(self)
^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolbase.py”, line 674, in init
self.__connect()
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolbase.py”, line 900, in __connect
with util.safe_reraise():
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyutillanghelpers.py”, line 146, in exit
raise exc_value.with_traceback(exc_tb)
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemypoolbase.py”, line 896, in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyenginecreate.py”, line 643, in connect
return dialect.connect(*cargs, **cparams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyenginedefault.py”, line 620, in connect
return self.loaded_dbapi.connect(*cargs, **cparams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespypyodbc.py”, line 2454, in init
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagessqlalchemyenginedefault.py”, line 620, in connect
return self.loaded_dbapi.connect(*cargs, **cparams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespypyodbc.py”, line 2454, in init
return self.loaded_dbapi.connect(*cargs, **cparams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespypyodbc.py”, line 2454, in init
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespypyodbc.py”, line 2454, in init
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespypyodbc.py”, line 2454, in init
self.connect(connectString, autocommit, ansi, timeout, unicode_results, readonly)
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespypyodbc.py”, line 2507, in connect
check_success(self, ret)
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespypyodbc.py”, line 1009, in check_success
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespypyodbc.py”, line 1009, in check_success
ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h, ret, ODBC_obj.ansi)
File “C:UsersantoaAppDataRoamingPythonPython312site-packagespypyodbc.py”, line 987, in ctrl_err
raise DatabaseError(state,err_text)
raise DatabaseError(state,err_text)
sqlalchemy.exc.DatabaseError: (pypyodbc.DatabaseError) (‘08001’, ‘[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.’)
(Background on this error at: https://sqlalche.me/e/20/4xp6)

“—————————————————————————————-“

SQL CODE:

CREATE TABLE IF NOT EXISTS “SQLtoPY”.”AdariaGroup”
(
id integer NOT NULL,
name character varying COLLATE pg_catalog.”default”,
email character varying COLLATE pg_catalog.”default”
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS “SQLtoPY”.”AdariaGroup”
OWNER to postgres;

New contributor

Antoan Shopov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật