0

I'm trying to insert a row with a raspberry pi on a wamp's database which is established on my PC. Both devices are connected to same router, i've made a user privilegues for the RPi, but when i try to connect to the database, the code stuck to the connector.Connect function and no exception is catched. This is the used code:

from mysql import connector

print('0')
try:
    con = connector.Connect(user='own_pi',password='password',database='tempbase',host='192.168.0.104', port=3306)
except connector.Error as e:
    print("Error code:", e.errno)        # error number
    print("SQLSTATE value:", e.sqlstate) # SQLSTATE value
    print("Error message:", e.msg)       # error message
    print("Error:", e)                   # errno, sqlstate, msg values
    s = str(e)
    print("Error:", s)                   # errno, sqlstate, msg values

print('1')
cur = con.cursor()
print('2')
cur.execute("INSERT INTO `sensor_readings` (`uid`, `local_id`, `type`, `date`, `reading`) VALUES ('7', '4', 'temperature', '2018-06-04', '24.4');")
print('3')
con.commit()
print('4')
con.close()
print('5')

This print('1') line is never invoked and the process stays forever alive.

Do you have any idea what could provoke such a behaviour and how can I fix it?

2 Answers2

0

Try using:

from mysql import connector

print('0')
try:
    con = connector.Connect(user='own_pi',password='password',database='tempbase',host='192.168.0.104', port=3306)
    print('1')

    cur = con.cursor()
    print('2')
    cur.execute("INSERT INTO `sensor_readings` (`uid`, `local_id`, `type`, `date`, `reading`) VALUES ('7', '4', 'temperature', '2018-06-04', '24.4');")
    print('3')
    con.commit()
    print('4')
    con.close()
    print('5')

except connector.Error as e:
    print("Error code:", e.errno)        # error number
    print("SQLSTATE value:", e.sqlstate) # SQLSTATE value
    print("Error message:", e.msg)       # error message
    print("Error:", e)                   # errno, sqlstate, msg values
    s = str(e)
    print("Error:", s)                   # errno, sqlstate, msg values
kaxil
  • 17,706
  • 2
  • 59
  • 78
0

The rootcause of the issue were the Windows 10 default Firewall settings. Thank you for the support.