请求库未发送请求

如果我手动发送第二个请求,它可以正常工作,但是如果我尝试通过python执行此操作,它将失败。apache 日志中没有错误。文件保持不变,不会被覆盖。法典:


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



$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);

?>


一只斗牛犬
浏览 116回答 1
1回答

小怪兽爱吃肉

如果我理解你想做什么,我认为你的if语句实际上并没有检查你想要什么。根据您的评论,它应该是:if mode == 1: # 1-> Read 2-> Write&nbsp; &nbsp; params = {'mode':'readFen'}elif mode == 2:&nbsp;&nbsp; &nbsp; params = {'mode':'putFen','fen':fen}&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python