Jan-04-2019, 10:02 PM
I have a python server and when i ask the client the login name to check it is valid with the 1 in the database, for some reason there is always a whitespace at the end of the string. I already tried this:
Here is a code snippet from the server:
Let's say there is an account name oliver in the data base and the client sends oliver. For some some reason i don't know is the string length 7 and not 6 and this makes comparing the value with the value from the database imposseble
1 2 3 4 5 |
newstring = oldstring.replace( ' ' , '') #not working, white space is still there newstring = oldstring.strip() # also not working, whitespace is still there #i also tried: newstring = oldstring.replace( '\n\t\r\s\f' , '') #not working, white space is still there |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
client_loggedin = False while client_loggedin = = False : accountName = conn.recv( 1024 ).decode( "utf_8" ) print (accountName + " = " + str ( len (accountName))) db = pymysql.connect( "XXXXXXXXXXXXXsecretXXXXXXXXXX" ) cursor = db.cursor() cursor.execute( "SELECT `XXXXXXXXXXXXX` FROM `XXXXXXXXXXXXX` WHERE `XXXXXXXXXXXXX`=%s" , accountName) dataraw = cursor.fetchone() data = dataraw[ 0 ] db.close() if str (accountName) ! = str (data): print ( str (data) + "+" + str (accountName)) print ( "datalengte: " + str ( len (data)) + " en " + "accountNamelengte: " + str ( len (accountName))) print ( "Deze gebruiker bestaat niet" ) elif accountName = = data: reply = "Welcome " + str (accountName) conn.sendall(reply.encode( "utf_8" )) client_loggedin = = True for x in clientList: if x ! = conn: x.sendall(( str (accountName) + " has joined the server" ).encode( "utf_8" )) |