Error When Writing to SQL Table - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Error When Writing to SQL Table (/thread-27533.html) |
Error When Writing to SQL Table - skaailet - Jun-09-2020 Im getting an error "the machine refuses it" when running my script to write to a table from pylogix import PLC import sys sys.path.append('..') import time import pymysql with PLC() as comm: comm.IPAddress = '172.21.12.10' comm.ProcessorSlot = 0 ret = comm.GetPLCTime() print( "Fecha y Hora de Registro Revision Fallas", ret.Value) time.sleep(1) Estacion = "D2R_030" print("Connecting To Database") connection = pymysql.connect(host='ACTWSLT01', user='METALSA\satmslt', password='T$m@l19*', db='Python_PLC') cursor = connection.cursor() print("Connected") #------------------------------------------------------------------------------------------ ESTACION D2R_030 -------------------------------------------------------------------------------# print("INICIO DE REVISION ESTACION :" , Estacion) #ACTUADOR 1 ACTUADOR = comm.Read('D2R_030.Status.Act._1.WBypassed') ret = comm.GetPLCTime() Numero_Act_EnBypass = 0 if ACTUADOR.Value == True: Sensor = "ACTUADOR 1 WORK SENSOR EN BY PASS" Numero_Act_EnBypass= (Numero_Act_EnBypass+1) sql = "INSERT INTO 'PLC Actuadores' ('Id', 'IP', 'Date', 'Estacion', 'Tag', 'Value') VALUES (%s, %s, %s, %s, %s)" cursor.execute(sql,(comm.IPAddress, ret.Value, Estacion, ACTUADOR, Sensor)) plc_data = plc_data.append(temp_dict.copy(), ignore_index=True) plc_data.to_excel("Actuadores.xlsx", sheet_name='Result', index=False) print(Sensor) connection.commit() else: Sensor = "ACTUADOR 1 WORK OK" print(Sensor) comm._closeConnection connection.close() print("Terminado")
RE: Error When Writing to SQL Table - bowlofred - Jun-10-2020 It's saying the python script tried to connect to the mysql server and wasn't able to. Could be access restrictions or firewalls. |