folgendes Problem.
Ich habe 2 100% identische Raspbian Systeme auf Raspberrys laufen.
ich möchte nun das System 1 auf die Datenbank von System 2 schreibt.
Habe das komplette Script bereits fertig, und jedes System kann auch auf seine eigene Datenbank schreiben, falls ich jedoch statt localhost die IP eines der anderen Systeme angebe bekomme ich folgenden Error in der Konsole und das Programm beendet:
Traceback (most recent call last):
File "hausfunk.py", line 44, in <module>
db = MySQLdb.connect("192.168.0.112","root","***","hausfunk" )
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on '192.168.0.112' (111)")
Ich kann mir das Problem beim besten Willen nicht erklären, weswegen ich mir jetzt auch nicht sicher bin welchen Teil des Codes ich am besten hier poste, hier ist einfach mal der part beim absenden
Code: Alles auswählen
if mes != 0:
if empf == 2:
# Open database connection
db = MySQLdb.connect("192.168.0.104","root","***","hausfunk" )
elif empf == 3:
# Open database connection
db = MySQLdb.connect("192.168.0.104","root","***","hausfunk" )
elif empf == 1:
# Open database connection
db = MySQLdb.connect("192.168.0.112","root","***","hausfunk" )
print "vor if"
if mes == 1: #hier ein oder alle
sql = """INSERT INTO Nachrichtenein(Sender,
Nachricht)
VALUES ('Stefan', 'Nachricht')"""
print "in if"
elif mes == 2:
sql = """INSERT INTO Nachrichtenein(Sender,
Nachricht)
VALUES ('Stefan', 'Nachricht')"""
elif mes == 3:
sql = """INSERT INTO Nachrichtenein(Sender,
Nachricht)
VALUES ('Stefan', 'Nachricht')"""
elif mes == 4:
sql = """INSERT INTO Nachrichtenein(Sender,
Nachricht)
VALUES ('Stefan', 'Nachricht')"""
elif mes == 5:
sql = """INSERT INTO Nachrichtenein(Sender,
Nachricht)
VALUES ('Stefan', 'Nachricht')"""
elif mes == 6:
sql = """INSERT INTO Nachrichtenein(Sender,
Nachricht)
VALUES ('Stefan', 'Nachricht')"""
print "nach if"
try:
# Execute the SQL command
cursor.execute(sql)
# Commit your changes in the database
db.commit()
except:
# Rollback in case there is any error
db.rollback()
# disconnect from server
db.close()
mes = 0
empf = 0
Fenestro