无法使用Python3请求模块登录wordpress站点

无法使用Python3请求模块登录wordpress站点,python,wordpress,http,authentication,python-requests,Python,Wordpress,Http,Authentication,Python Requests,我正在编写一个python机器人来抓取wordpress站点,但我需要登录才能访问我想要的一些资源。代码如下: # username, password, and wp_login is defined above with requests.Session() as s: # store any initial cookies in the session s.get(wp_login) datas={ 'log':username, 'pwd':p

我正在编写一个python机器人来抓取wordpress站点,但我需要登录才能访问我想要的一些资源。代码如下:

# username, password, and wp_login is defined above

with requests.Session() as s:
    # store any initial cookies in the session
    s.get(wp_login)

    datas={
        'log':username, 'pwd':password, 'wp-submit':'Log In',
        'redirect-to':'', 'testcookie':'1'
    }

    # successful or unsuccessful login returns a 302 so I have to not allow
    # redirects or I can't view the response header to check for the cookies I need
    response = s.post(wp_login, data=datas, allow_redirects=False)

    print(response.status_code)
    print()
    print(response.request.headers)
    print()
    print(response.headers)
这是输出

302

{'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Cookie': '__cfduid=[REDACTED]', 'Content-Length': '57', 'Content-Type': 'application/x-www-form-urlencoded'}

{'Date': 'Mon, 30 Sep 2019 06:13:43 GMT', 'Content-Type': 'text/html; charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'X-Powered-By': 'PHP/5.6.32', 'X-Redirect-By': 'WordPress', 'Location': 'https://________/wp-login.php', 'Server': 'cloudflare', 'CF-RAY': '51e40d72d87c9691-SJC'}
我应该在成功登录时收到一个cookie,响应头中的重定向应该指向主页。所以身份验证失败了,我不明白为什么

编辑:在Chrome Developer tools中查看成功的POST请求时,具有以下数据字符串:

log=[username]&pwd=[password]&wp-submit=Log+In&redirect_to=&testcookie=1

是的,因为身份验证失败。我用我的数据向wp-login.php提交了一个POST请求,它将响应302。成功登录后,它会向我发送一个cookie,说明我已通过身份验证,并重定向到主页。登录失败后,它会将我重定向到wp-login.php,以便我可以尝试再次登录。您好,您好,亲爱的Holden Nelson,很高兴收到您的来信:感谢您在这种情况下支持我们。我很高兴我们是一个伟大而强大的社区,亲爱的霍尔顿-保持你的伟大:努力吧!!!非常感谢你所做的一切!!