If I send second request by hand, it works fine, but if I try to do that by python, it is failing. No errors in apache log. File remains the same and is not overwritten. Code:
def fen_actions(mode,fen): global url if mode: # 1-> Read 2-> Write params = {'mode':'readFen'} else: params = {'mode':'putFen','fen':fen} r = requests.get(url,params) return r.text fen_actions(2,chess.STARTING_BOARD_FEN) #This is not working. Starting fen is just a string temp_readed_fen = fen_actions(1,0) # This works
php code:
<?php $f = fopen("tempfen.txt","r+") or die("Unable to open a file"); if (strval($_GET["mode"]) === strval("putFen")) { if(strval($_GET['fen']) != strval(fread($f,filesize("tempfen.txt")))) { file_put_contents("tempfen.txt",""); fwrite($f,$_GET['fen']); } } else if ($_GET["mode"] === strval("readFen")) { echo(fread($f,filesize("tempfen.txt"))); } ini_set('display_errors',1); ?>
Advertisement
Answer
If I understand what you’re trying to do, I think your if statements aren’t actually checking what you want. According to your comment, it should be:
if mode == 1: # 1-> Read 2-> Write params = {'mode':'readFen'} elif mode == 2: params = {'mode':'putFen','fen':fen}