Python Forum
Error When Writing to SQL Table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error When Writing to SQL Table
#1
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")
Error:
Traceback (most recent call last): File "C:\Users\jsalass\AppData\Roaming\Python\Python38\site-packages\pymysql\connections.py", line 581, in connect sock = socket.create_connection( File "C:\Program Files (x86)\Python38-32\lib\socket.py", line 808, in create_connection raise err File "C:\Program Files (x86)\Python38-32\lib\socket.py", line 796, in create_connection sock.connect(sa) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\jsalass\Desktop\Prueba SQL.py", line 23, in <module> connection = pymysql.connect(host='ACTWSLT01', File "C:\Users\jsalass\AppData\Roaming\Python\Python38\site-packages\pymysql\__init__.py", line 94, in Connect return Connection(*args, **kwargs) File "C:\Users\jsalass\AppData\Roaming\Python\Python38\site-packages\pymysql\connections.py", line 325, in __init__ self.connect() File "C:\Users\jsalass\AppData\Roaming\Python\Python38\site-packages\pymysql\connections.py", line 630, in connect raise exc pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'ACTWSLT01' ([WinError 10061] No connection could be made because the target machine actively refused it)")
Reply
#2
It's saying the python script tried to connect to the mysql server and wasn't able to. Could be access restrictions or firewalls.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  i am getting error while writing code for exception logging rkgupta51179 1 1,814 Nov-03-2019, 05:12 AM
Last Post: buran
  writing bytes error qrani 4 2,873 Sep-22-2018, 09:00 PM
Last Post: qrani
  How to search and open an error file whose entity id is stored in hbase table lravikumarvsp 2 2,804 May-08-2018, 07:39 AM
Last Post: nilamo
  Error while writing a code for feature scaling prateek 1 2,482 Aug-15-2017, 09:17 PM
Last Post: Larz60+
  error while inserting values into a table from form in flask in postgreSQL sahilsiddharth 3 7,093 Jun-05-2017, 07:49 PM
Last Post: sahilsiddharth

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020