Как войти в Fantasy Premier League, используя python - PullRequest
0 голосов
/ 10 июля 2020

Как я могу получить достоверную информацию о сайте фэнтези-премьер-лиги. Ошибка аутентификации.

import requests 
from requests.auth import HTTPBasicAuth 
import aiohttp
import asyncio

session = requests.Session()


data = {
     "login" : "email", 
     "password" : "pass", 
     "app" : "plfpl-web", 
     "redirect_uri" : "https://fantasy.premierleague.com"
}


url = "https://users.premierleague.com/accounts/login/"
r = session.post(url, data=data)
print(r.status_code) # 200

url = ('https://fantasy.premierleague.com/api/my-team/{teamId}/')
r = requests.get(url)
json = r.json()
json.keys() # json object details says "Authentication credentials were not provided".

1 Ответ

0 голосов
/ 10 июля 2020

Вам необходимо убедиться, что вы сохраняете файлы cookie от вызова для входа в систему до вызова «команды». В частности, есть повар ie с именем pl_profile, который служит для аутентификации.

Вот фрагмент кода, который помогает:

s = requests.Session()

headers = {
   'authority': 'users.premierleague.com' ,
   'cache-control': 'max-age=0' ,
   'upgrade-insecure-requests': '1' ,
   'origin': 'https://fantasy.premierleague.com' ,
   'content-type': 'application/x-www-form-urlencoded' ,
   'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' ,
   'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' ,
   'sec-fetch-site': 'same-site' ,
   'sec-fetch-mode': 'navigate' ,
   'sec-fetch-user': '?1' ,
   'sec-fetch-dest': 'document' ,
   'referer': 'https://fantasy.premierleague.com/my-team' ,
   'accept-language': 'en-US,en;q=0.9,he;q=0.8' ,
}

data = {
    "login": "abc@def", 
    "password": "123456", 
    "app": "plfpl-web", 
    "redirect_uri": "https://fantasy.premierleague.com/"
}

url = "https://users.premierleague.com/accounts/login/"

res = s.post(url, data = data,  headers = headers)

team_url = "https://fantasy.premierleague.com/api/my-team/1234567/"
res = s.get(team_url)
json.loads(res.content)

Результат:

{'picks': [{'element': 123,
   'position': 1,
   'selling_price': 12,
   'multiplier': 1,
   'purchase_price': 13,
   ...
...