日志网站python带来错误 - 提供的防伪令牌验证失败

时间:2017-09-06 04:33:20

标签: python web python-requests antiforgerytoken

我正在使用Python登录网站https://app.whiskeysystems.com/并从中下载某些文件。但是,我收到了错误

  

Cookie __RequestVerificationToken和表单字段   __RequestVerificationToken被交换

我尝试过提供Antiforgery令牌,但仍然无法理解究竟是什么问题。

以下是我目前的代码(Windows 7上的Python 2.7,也将在MAC OS X上使用此代码):

import bs4

from bs4 import BeautifulSoup 

import requests 

import re 

import sys

import time

USER_AGENT = []


USER_AGENT.append('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36')

USER_AGENT.append('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36')

USER_AGENT.append('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36')

USER_AGENT.append('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1')

basic_URL = "https://app.whiskeysystems.com/Account/Login/"

complete_URL = basic_URL

print("\n**** Starting Program **** ")

print ("\nThe user-agent selected ---> " + USER_AGENT[2])
print("\nChecking if website ---> " + basic_URL +"  is UP or DOWN ?")

with requests.Session() as client:

    client.headers.update({'User-Agent':USER_AGENT[2]})
    c2 = client.get(complete_URL)  

    print("\nHTTP Status Code ---> " + str(c2.status_code))


    if ( int(c2.status_code) == 200):
        print("\nSuccessful!!!. Website is UP")

        print ("\nWill try to login to website using provided credentials")

        time.sleep(2)

        csrftoken = client.cookies['__RequestVerificationToken']
        print("\nThe __RequestVerificationToken value ---> " + str(csrftoken))

        time.sleep(1)
        login_data = dict(__RequestVerificationToken=csrftoken,Email='abc@def.com', Password='123456') 
        r1 = client.post(complete_URL, data=login_data)
        print r1.text


    else:
        print("\n Error !!!. Quitting the program, please see the website is UP or not. ")

0 个答案:

没有答案