如何使用Python请求开始会话?

时间:2019-04-04 21:50:43

标签: php python-3.x session request

我正在为大学做一个简单的PHP僵尸网络,正在做一个面板,以计算某个僵尸程序是在线还是离线,我想执行一个功能,如果该僵尸程序每隔X秒不发出请求,机器人会离线。 我最终决定使用这些会议。 (我已设置为会话每20秒过期一次,如果您不重新更新,则该漫游器会基于所有IP关闭。)

我的机器人向file/gate.php发送了一个请求(Python 3模块)。当漫游器离线时,它将初始化一个持续20秒的会话。

如果我“手动”进入我的/gate.php,我的/welcome.php(所有bot表都在其中,则On / Off选项起作用,并且lastaccess受到支持。当我开始测试Python脚本时,我会一些像这样:

url = "http://127.0.0.1:90/gate.php"

headers = {
    'User-Agent': 'My User Agent 1.0',
    'From': 'lol@domain.com'  # This is another valid field
}

while True:
    try:
        r = requests.post(url,headers=headers)
    except requests.ConnectionError as err:
        sleep(5)
        print(err)
        r = requests.get("http://localhost:90/gate.php")
    except requests.HTTPError as err:
        print(err)
        sleep(5)
    r = requests.get("http://localhost:90/gate.php")

问题是,当我运行此请求工作时,lastaccess每次都会上载,但是“ On / off”选项不会更改,就像用户代理运行不正常一样

对请求的回答不是错误的,我认为问题是未通过正确的useragent会话不会启动,但是我不知道如何解决。

UP:即使来自终端的简单请求卷曲也不起作用。

0 个答案:

没有答案