Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Attendence System
#16
(Dec-20-2016, 06:41 PM)nilamo Wrote: Try pinging the server after you've got a connection, but before trying to make a cursor.  That way you can make sure the database is running and you're connected.  https://dev.mysql.com/doc/connector-pyth...-ping.html  

You could also skip the cursor and use the connection directly with .cmd_query(): https://dev.mysql.com/doc/connector-pyth...query.html

ok so i tried to ping the server and i still gives me a big error. NEW code
import time


import mysql.connector


from mysql.connector import errorcode


from datetime import datetime


try:
   cnx = mysql.connector.connect(user='root', password='password', database='staff', host='localhost')
   
except mysql.connector.Error as err:
   if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
       print("Something is wrong with your username or password")
   elif err.errno == errorcode.ER_BAD_DB_ERROR:
       print("Database does not exist")
   else:
       print(err)
else:
   cnx.close()


cnx.ping(attempts=1,delay=0)
Then i get the error
Error:
OSError                                   Traceback (most recent call last) /home/Elliott/Documents/ana/lib/python3.5/site-packages/mysql/connector/network.py in send_plain(self, buf, packet_number)    129                 else: --> 130                     self.sock.sendall(packet)    131             except IOError as err: OSError: [Errno 9] Bad file descriptor During handling of the above exception, another exception occurred: OperationalError                          Traceback (most recent call last) /home/Elliott/Documents/ana/lib/python3.5/site-packages/mysql/connector/connection.py in ping(self, reconnect, attempts, delay)   1011         try: -> 1012             self.cmd_ping()   1013         except: /home/Elliott/Documents/ana/lib/python3.5/site-packages/mysql/connector/connection.py in cmd_ping(self)    874         """ --> 875         return self._handle_ok(self._send_cmd(ServerCmd.PING))    876 /home/Elliott/Documents/ana/lib/python3.5/site-packages/mysql/connector/connection.py in _send_cmd(self, command, argument, packet_number, packet, expect_response)    503                 self._protocol.make_command(command, packet or argument), --> 504                 packet_number)    505         except AttributeError: /home/Elliott/Documents/ana/lib/python3.5/site-packages/mysql/connector/network.py in send_plain(self, buf, packet_number)    132                 raise errors.OperationalError( --> 133                     errno=2055, values=(self.get_address(), _strioerror(err)))    134             except AttributeError: OperationalError: 2055: Lost connection to MySQL server at 'localhost:3306', system error: 9 Bad file descriptor During handling of the above exception, another exception occurred: InterfaceError                            Traceback (most recent call last) <ipython-input-6-ee7505b13fb4> in <module>() ----> 1 cnx.ping(attempts=1,delay=0) /home/Elliott/Documents/ana/lib/python3.5/site-packages/mysql/connector/connection.py in ping(self, reconnect, attempts, delay)   1015                 self.reconnect(attempts=attempts, delay=delay)   1016             else: -> 1017                 raise errors.InterfaceError("Connection to MySQL is"   1018                                             " not available.")   1019 InterfaceError: Connection to MySQL is not available.
Sorry for the big errors and for me being not very good at python. :) I have learned loads over the last few days and i thank you all for your help.
Reply


Messages In This Thread
Attendence System - by elliott0184 - Dec-12-2016, 03:21 PM
RE: Attendence System - by nilamo - Dec-12-2016, 05:11 PM
RE: Attendence System - by micseydel - Dec-12-2016, 09:25 PM
RE: Attendence System - by elliott0184 - Dec-12-2016, 10:04 PM
RE: Attendence System - by nilamo - Dec-12-2016, 11:21 PM
RE: Attendence System - by elliott0184 - Dec-13-2016, 09:43 AM
RE: Attendence System - by nilamo - Dec-13-2016, 05:20 PM
RE: Attendence System - by elliott0184 - Dec-14-2016, 10:05 AM
RE: Attendence System - by DennisT - Dec-14-2016, 09:38 PM
RE: Attendence System - by elliott0184 - Dec-20-2016, 06:01 PM
RE: Attendence System - by nilamo - Dec-20-2016, 06:13 PM
RE: Attendence System - by elliott0184 - Dec-20-2016, 06:22 PM
RE: Attendence System - by wavic - Dec-20-2016, 06:30 PM
RE: Attendence System - by elliott0184 - Dec-20-2016, 06:30 PM
RE: Attendence System - by nilamo - Dec-20-2016, 06:41 PM
RE: Attendence System - by elliott0184 - Dec-21-2016, 01:11 PM
RE: Attendence System - by Larz60+ - Dec-21-2016, 01:36 PM
RE: Attendence System - by elliott0184 - Dec-21-2016, 01:47 PM
RE: Attendence System - by elliott0184 - Dec-21-2016, 06:27 PM
RE: Attendence System - by elliott0184 - Feb-21-2017, 03:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 16,779 Jan-11-2021, 06:30 PM
Last Post: ykumar34
Question Difference between Python's os.system and Perl's system command Agile741 13 6,981 Dec-02-2019, 04:41 PM
Last Post: Agile741

Forum Jump:

User Panel Messages

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