[python]if / else geht nicht

07/07/2016 18:50 FireFox©#1
Hallo Com,

Da ich momentan daran bin eine etwas abgewandelte Version von Raiguard in meinen Client zu implementieren(Nein die Licence vom ersteller will ich nicht entfernen)bin ich auf einen sehr komischen Fehler gestoßen und vielleicht kann einer der Lieben Python götter mir hier helfen.

Kurz zum System:
Wenn man sich einloggt wird eine abfrage an den Server gestellt zwecks des Status des Guards.

0 = Aus
1 = An

Das ganze läuft über eine Php seite ähnlich wie bei raiguard:
PHP Code:
$accountdb_ip "xxxxxx"//Accountserver-IP
$accountdb_login "xxxxx"//Accountserver-Loginname
$accountdb_pw "xxxxxxxx"//Accountserver-Passwort
$db_ip "xxxxxxxx"//DB-Server-IP
$db_login "xxxxxx"//DB-Server-Loginname
$db_pw "xxxxxxx"//DB-Server-Passwort

$con mysql_connect($db_ip$db_login$db_pw);
$con_account mysql_connect($accountdb_ip$accountdb_login$accountdb_pw);
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }
  
$pcid mysql_real_escape_string($_GET["pcid"], $con);
$login mysql_real_escape_string($_GET["login"], $con);
if(
$login != "" ){
$result_id mysql_query("SELECT * FROM account.account WHERE login='".$login."' LIMIT 1"$con);
$player_acc_id mysql_result($result_id0"id");
$result mysql_query("SELECT * FROM account.account WHERE id='".$player_acc_id."'"$con);
$status mysql_result($result0"raiguard");

if(
$status == 0)
    {echo 
"0";}
elseif(
$status == 1)
    {echo 
"1";}
elseif(
$status == 2)
    {echo 
"2";}
}

if(
$pcid != ""){
$result_id mysql_query("SELECT * FROM account.account WHERE login='".$pcid."' LIMIT 1"$con);
$player_acc_id mysql_result($result_id0"id");
$result mysql_query("SELECT * FROM account.account WHERE id='".$player_acc_id."'"$con);
$status mysql_result($result0"raiaccpin");
echo 
$status;    
}
mysql_close($con);
mysql_close($con_account); 
(Ja ich weiß das da eine mysql verbindung umsonst ist ;D fein tuneing)
Sie gibt erfolgreich bei ?login=accname oder ?pcid= Den Status 0 oder 1 oder den Pin aus.

nun zum script:
PHP Code:
def __OnClickLoginButton(self):
        
id self.idEditLine.GetText()
        
pwd self.pwdEditLine.GetText()
        
logintest str(id)
        
#dbg.LogBox(logintest)
        
protect urllib2.urlopen(HOMEPAGE "raiguardstatusig.php?login=" logintest).read()
        
dbg.LogBox(protect)
        
        
        if (
protect == "1"):
        
            if 
len(id)==0:
                
self.PopupNotifyMessage(localeInfo.LOGIN_INPUT_IDself.SetIDEditLineFocus)
            return

            if  
len(pwd)==0:
                
self.PopupNotifyMessage(localeInfo.LOGIN_INPUT_PASSWORDself.SetPasswordEditLineFocus)
            return
        
            
self.Connect(idpwd)
            
        else:
        
            
dbg.LogBox("Schon wieder fail!"
So das hier habe ich auch getestet also der client bekommt aus protect variable = 1 .

Der Fehler ist aber obwohl ich es hier mit:
PHP Code:
if (protect == "1"): 
gemacht habe springt er auch bei
PHP Code:
protect=
auf
PHP Code:
else:
        
            
dbg.LogBox("Schon wieder fail!"
ich habe auch schon:
PHP Code:
if (protect == "1"):
if (
protect == '1'):
if (
protect == 1):
if 
protect == "1"
if protect == '1':
if 
protect == 1
getestet aber ohne erfolg leider.

Ich nehme an das er aus der Homepage zusätzlich ein leerzeichen/zeile mit nimmt.Jetzt ist meinen frage wie ich es hinbekomme das er hier nicht die If bedingung überspringt sprich das protect = clientvariable ist.

Danke für eure Hilfe im Vorfeld
Mfg Fabejan

PS:Rechtschreibfehler bitte schenken(außer sie sind im code);D:handsdown:
07/07/2016 18:55 MaxChri#2
Schau dir mal if clauses an:

[Only registered and activated users can see links. Click Here To Register...]
07/07/2016 19:25 FireFox©#3
Danke aber auch mit
PHP Code:
if protect != 0:
              if  
len(pwd)==0:
            
self.PopupNotifyMessage(localeInfo.LOGIN_INPUT_PASSWORDself.SetPasswordEditLineFocus)
              else:
            
self.Connect(idpwd)
            
       else:
            
dbg.LogBox("Schon wieder fail!"
oder
PHP Code:
if protect:
        if  
len(pwd)==0:
            
self.PopupNotifyMessage(localeInfo.LOGIN_INPUT_PASSWORDself.SetPasswordEditLineFocus)
        else:
            
self.Connect(idpwd)
        
      else:
        
dbg.LogBox("Schon wieder fail!"
gehts es nicht da protect niemals = null/none ist aber ich versteh auch nicht warum es nicht mit != 0 geht das heißt ja alles was nicht 0 ist wird reingelassen aber auch ein char der bei protect 0 hat wird reingelassen irgenwas mit der übergabe abspeicherung String Int float idk=?
07/07/2016 19:45 MaxChri#4
Versuch mal

Code:
if protect != "0":
07/07/2016 20:04 FireFox©#5
Danke habe es schon:
urllib hat "\n" mitgenommen nur zu sehen in der python console ich dummy ;D habe mich so auf dbg.LogBox versteift.

Lösung für alle die das noch einmal haben

python console open
type in
>>> import urllib
>>> urllib.urlopen("xxxxxxxxxxxxxxxxxxxxxxxxx").read()
ausgabe
'1\n'


Lösung: protect = protect.strip() # entfernt das \n
if protect = "0": geht dann

Danke für deine Hilfe