无法使用cURL

时间:2018-03-12 23:27:32

标签: google-chrome curl login

我想使用Python的requests模块登录网页https://www.tennistv.com/login。使用Chrome的开发人员工具,我查看了点击登录按钮后发送的请求的外观。

使用https://www.tennistv.com/api/users/v1/login形式的JSON有效内容生成对URL {"Email":"[MAIL]","Password":"[PASSWORD]"}的POST请求。但是我无法使用Python的请求模块和cURL。 Chrome的开发人员工具可以选择使用请求生成cURL命令。这就是我所做的,但即使是cURL请求也会产生以下错误:

{
    "error": {
        "validationErrors": [{
            "key": "loginModel",
            "value": [""]
        }],
        "errorMessage": "There was an error while validating input data (UR001)",
        "errorCode": "UR001",
        "userErrorCode": "UR001"
    }
}

生成的cURL请求如下所示:

curl "https://www.tennistv.com/api/users/v1/login" -H "Pragma: no-cache" -H "Origin: https://www.tennistv.com" -H "Accept-Encoding: gzip, deflate, br" -H "Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36" -H "content-type: application/json" -H "Accept: */*" -H "Cache-Control: no-cache" -H "Referer: https://www.tennistv.com/login" -H "Connection: keep-alive" --data-binary "^{^\^"Email^\^":^\^"[MAIL]^\^",^\^"Password^\^":^\^"[PASS]^\^"^}" --compressed

Chrome的请求如下所示:

enter image description here

如何让cURL请求生效? Chrome和cURL发送的请求之间有什么区别?

1 个答案:

答案 0 :(得分:0)

试试这个cURL:

curl -v "https://www.tennistv.com/api/users/v1/login" \
-H "Pragma: no-cache" \
-H "Origin: https://www.tennistv.com" \
-H "Accept-Encoding: gzip, deflate, br" \
-H "Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7" \
-H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36" \
-H "content-type: application/json" \
-H "Accept: */*" \
-H "Cache-Control: no-cache" \
-H "Referer: https://www.tennistv.com/login" \
-H "Connection: keep-alive" \
--data-binary '{"Email":"foobar@domain.tld","Password":"xxx"}'

(使用您的凭据编辑最后一行)