python3请求400错误请求

时间:2017-05-27 18:00:08

标签: python python-requests

我尝试使用请求登录网页但我得到了这个原因(400 Bad Request)

我尝试的是:

谷歌Chrome浏览器首先检查:

1img

2img

我的代码:

import requests

from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)


headers = {
    "Content-Type":"application/x-www-form-urlencoded",
    "User-Agent" : "Mozilla/5.0",
    "Referer": "https://doit.voicemail.centurylink.net/login",
}


data = {
    "DirectoryNumber": "1234567890",
    "Password": "1234567890",
    "next": "/"
}

with requests.Session() as c:

    response = c.post(url='https://doit.voicemail.centurylink.net/login',
        headers=headers,
        data=data,
        verify=False)

    print(response.history, response.url, response.status_code, response.reason)

我该怎么做?

1 个答案:

答案 0 :(得分:1)

我访问了您的网站,发现可能您需要发送数据的方式是:

data = MultipartEncoder(
    fields=(
            ('DirectoryNumber', '1234567890'), 
            ('Password', '1234567890'),
            ('next', '/')
           )
    )

with requests.Session() as c:

    response = c.post(url='https://doit.voicemail.centurylink.net/login',
        headers=headers,
        data=data,
        verify=False)

也许它不是' next'但是' redirectTo'你必须指定