Написал код, который должен возвращать все номенклатуры
import win32com.client
import pythoncom
def connect_to_1c():
try:
pythoncom.CoInitialize()
v8 = win32com.client.Dispatch("V83.Application")
connection_string = "File='C:\\Users\\USER\\OneDrive\\Документы\\1C\\SmallBusinessEduc'"
connected = v8.Connect(connection_string)
if connected:
return v8
else:
print("Failed to connect to 1C.")
return None
except Exception as e:
print(f"Error connecting to 1C: {e}")
return None
def execute_query(connection, query):
try:
query_obj = connection.NewObject("Query", query)
result = query_obj.Execute()
while not result.EOF:
record = result.Current
for field in record:
print(field)
result.Next()
except Exception as e:
print(f"Failed to execute query: {e}")
if __name__ == "__main__":
connection = connect_to_1c()
if connection:
query = "SELECT * FROM Справочник.Номенклатура"
execute_query(connection, query)
Но на выходе получаю ошибку
Error connecting to 1C: (-2147417848, 'The object invoked has disconnected from its clients.', None, None)