Почтовый запрос работает через Postman, но не через библиотеку Python Requests - PullRequest
0 голосов
/ 14 октября 2018

Я пытаюсь очистить данные с www.thetipsterleague.com, и я сделал рабочий запрос в Postman, который получает n-ую страницу данных, однако и мой код, и код, который Postman говорит использовать, возвращает следующую ошибкукоторый я не смог исправить:

requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

Мой код:

import requests

url = "https://www.thetipsterleague.com/ajax/tipster-tips"

params = {
    "_token":"xNsJwhPG8zm5XryZPRPfXSjWfS3DE2R563TB3737",
    "id":"85",
    "page":"4"
}

headers = {
    "Host": "www.thetipsterleague.com",
    "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0",
    "Accept": "*/*",
    "Accept-Language": "en-GB,en;q=0.5",
    "Accept-Encoding": "gzip, deflate, br",
    "Referer": "https://www.thetipsterleague.com/tipster/hugh-taylor",
    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
    "X-Requested-With": "XMLHttpRequest",
    "Content-Length": "60",
    "Cookie": r"_omappvp=c12MNO2hmCaipvfx8m143s2yvPQixQVYOgLVUpkOLA1rySNAYeCUqsVc5oHnOwOxsxsOMYre5XsnlfKS0Rc6qXXRCRFEc7kn; _drip_client_8304301=vid%253D01c281f0b0f90136c7dd12348dd749b6%2526pageViews%253D16%2526sessionPageCount%253D1%2526lastVisitedAt%253D1539511134903%2526weeklySessionCount%253D3%2526lastSessionAt%253D1539511134903; _ga=GA1.2.1744392981.1539423228; _gid=GA1.2.1903882760.1539423228; om-n9lcrkxxzjauwgdzivkh=1539423673834; XSRF-TOKEN=eyJpdiI6InB3RjN0MDl6cTY1MTlsaE9md29qTkE9PSIsInZhbHVlIjoiT2MzZ3p5NHJndGozd21sdEJxaTM1RWpUN1cxTDNsUm4wRGhYZ0VzMFBQVWhuXC9xT09NK1g4Sm1EQU1HeEtWYWhJQytqV1BtaUU5TDRSTGhNUjdCSnF3PT0iLCJtYWMiOiJmOGY1ZmY5YTlkNjM0YzgyNWE3ZWNhNDljZTM0MTM4NTY1MDBmNTJjMGY1MGI0NDQ5NTM5MDg0MTE1MTk5NzIwIn0%3D; laravel_session=eyJpdiI6InhSakR3SWNHajdyTkYwa2hTcURzY3c9PSIsInZhbHVlIjoiNzVpN2Jlb0xpMXc1S21SQ3U0cjk3OGNzVTU1b0h6R0hET21PU0VYalZQdDBGQ2lnOU84MlNGV0Ftczd0ZGNPclNlTzFSRDJPN0hYWVJveFF0YThZeWc9PSIsIm1hYyI6IjViNWM5MDZjYTVmMDFhMDMzOTI5NTYxYjczNTliMDI2Mzg3YjA0MWY5OWM3NmZjZWIzYTAxODAwNzU4ZTY4ZTQifQ%3D%3D; _gat_gtag_UA_115644339_1=1; _hjIncludedInSample=1",
    "Connection": "keep-alive",
    "TE": "Trailers"
}

r = requests.post(url, headers = headers, params = params)

print(r.text)

Код почтальона:

import requests

url = "https://www.thetipsterleague.com/ajax/tipster-tips"

querystring = {"_token":"xNsJwhPG8zm5XryZPRPfXSjWfS3DE2R563TB3737","id":"85","page":"4"}

headers = {
    'Host': "www.thetipsterleague.com",
    'User-Agent': "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0",
    'Accept': "*/*",
    'Accept-Language': "en-GB,en;q=0.5",
    'Accept-Encoding': "gzip, deflate, br",
    'Referer': "https://www.thetipsterleague.com/tipster/hugh-taylor",
    'Content-Type': "application/x-www-form-urlencoded; charset=UTF-8",
    'X-Requested-With': "XMLHttpRequest",
    'Content-Length': "60",
    'Cookie': "_omappvp=c12MNO2hmCaipvfx8m143s2yvPQixQVYOgLVUpkOLA1rySNAYeCUqsVc5oHnOwOxsxsOMYre5XsnlfKS0Rc6qXXRCRFEc7kn; _drip_client_8304301=vid%253D01c281f0b0f90136c7dd12348dd749b6%2526pageViews%253D16%2526sessionPageCount%253D1%2526lastVisitedAt%253D1539511134903%2526weeklySessionCount%253D3%2526lastSessionAt%253D1539511134903; _ga=GA1.2.1744392981.1539423228; _gid=GA1.2.1903882760.1539423228; om-n9lcrkxxzjauwgdzivkh=1539423673834; XSRF-TOKEN=eyJpdiI6InB3RjN0MDl6cTY1MTlsaE9md29qTkE9PSIsInZhbHVlIjoiT2MzZ3p5NHJndGozd21sdEJxaTM1RWpUN1cxTDNsUm4wRGhYZ0VzMFBQVWhuXC9xT09NK1g4Sm1EQU1HeEtWYWhJQytqV1BtaUU5TDRSTGhNUjdCSnF3PT0iLCJtYWMiOiJmOGY1ZmY5YTlkNjM0YzgyNWE3ZWNhNDljZTM0MTM4NTY1MDBmNTJjMGY1MGI0NDQ5NTM5MDg0MTE1MTk5NzIwIn0%3D; laravel_session=eyJpdiI6InhSakR3SWNHajdyTkYwa2hTcURzY3c9PSIsInZhbHVlIjoiNzVpN2Jlb0xpMXc1S21SQ3U0cjk3OGNzVTU1b0h6R0hET21PU0VYalZQdDBGQ2lnOU84MlNGV0Ftczd0ZGNPclNlTzFSRDJPN0hYWVJveFF0YThZeWc9PSIsIm1hYyI6IjViNWM5MDZjYTVmMDFhMDMzOTI5NTYxYjczNTliMDI2Mzg3YjA0MWY5OWM3NmZjZWIzYTAxODAwNzU4ZTY4ZTQifQ%3D%3D; _gat_gtag_UA_115644339_1=1; _hjIncludedInSample=1",
    'Connection': "keep-alive",
    'TE': "Trailers",
    'Cache-Control': "no-cache",
    'Postman-Token': "0652cfcc-a36f-4fc0-8b8f-5b0600ab021c"
    }

response = requests.request("POST", url, headers=headers, params=querystring)

print(response.text)

Заголовки, которые я только что скопировал сконсоль Firefox.

РЕДАКТИРОВАТЬ: _token меняется очень часто.

...