Php 带请求的Python长轮询模式

Php 带请求的Python长轮询模式,php,python,python-requests,long-polling,Php,Python,Python Requests,Long Polling,我正在使用服务器上的PHP脚本和MySQL数据库以及客户端上的python脚本执行长轮询模式。 如果数据库中的标志设置为0,PHP页面将用元组的id进行响应。如果请求超时,则应启动新请求。这是我的代码,我找不到我的错误: gotID = False ID = 0 while gotID == False: f = requests.get("http://example.de/ajax_backend.php") print("status: " + str(f.status_

我正在使用服务器上的PHP脚本和MySQL数据库以及客户端上的python脚本执行长轮询模式。 如果数据库中的标志设置为0,PHP页面将用元组的id进行响应。如果请求超时,则应启动新请求。这是我的代码,我找不到我的错误:

gotID = False
ID = 0

while gotID == False:
    f = requests.get("http://example.de/ajax_backend.php")
    print("status: " + str(f.status_code))
    print("content: " + f.text)
    if int(f.status_code) == 200:
        gotID = True
        ID = f.text
如果我像这样运行代码,我会得到这个输出。首先,标志被设置为1,然后在中间,我将标志改为0:


我认为
if
语句中有错误,但我找不到它。你能帮我吗?

我现在创建了一个工作代码:

gotID = None
ID = 0

while not gotID:
    f = requests.get("http://example.de/ajax_backend.php")
    print("status: " + str(f.status_code))
    print("content: " + f.text)

    try:
        ID = int(f.text)
        gotID = "samlpe content"
    except ValueError:
        gotID = None

但我仍然不知道为什么我上面的代码不起作用

我现在创建了一个工作代码:

gotID = None
ID = 0

while not gotID:
    f = requests.get("http://example.de/ajax_backend.php")
    print("status: " + str(f.status_code))
    print("content: " + f.text)

    try:
        ID = int(f.text)
        gotID = "samlpe content"
    except ValueError:
        gotID = None

但我仍然不知道为什么我上面的代码不起作用

请发布两种情况(设置和取消设置标志)的原始响应。问题是什么?是否即使
f.status\u code
返回500,它也会退出循环?问题是,无论标志设置为1还是0,程序都会停留在while循环中。如果标志设置为1,程序应离开while循环。请发布两种情况(设置和取消设置标志)的原始响应。问题是什么?是否即使
f.status\u code
返回500,它也会退出循环?问题是,无论标志设置为1还是0,程序都会停留在while循环中。如果标志设置为1,程序应离开while循环。