alan-turing-institute / AIrsenal

Machine learning Fantasy Premier League team
MIT License
287 stars 86 forks source link

run_optimization ValueError(f"No transactions in database for team ID {fpl_team_id}") #688

Open ElliottTDon opened 3 weeks ago

ElliottTDon commented 3 weeks ago

Updated for my squad after GW1 and issues with accessing team API "UserWarning: Failed to get current squad from API: Unable to access FPL API: 404 Client Error: Not Found for url: https://fantasy.premierleague.com/api/my-team/2115508/" and subsequently not adding transactions to the database for the team ID.

nbarlowATI commented 3 weeks ago

Hi @ElliottTDon , if you sign-in on the FPL website, then point your browser to that URL, https://fantasy.premierleague.com/api/my-team/2115508/, does it show the json data of your "picks"? If not, have you double-checked that you've got the correct FPL_TEAM_ID ? (when on the FPL website you look at the "Points" tab, the URL should be https://fantasy.premierleague.com/entry/{FPL_TEAM_ID}/event/1/ )

If you are able to view the json data in your browser when you're logged in, could it be an issue with the FPL_LOGIN and FPL_PASSWORD variables you've defined? When you first run the optimization step airsenal_run_optimization, do you get a message about succeeding or failing to login? (For some reason for us it always seems to fail the first attempt but then succeed on the second).

ElliottTDon commented 3 weeks ago

Hi @nbarlowATI - thanks for your response.

I have updated the credentials and it logs in correctly. This is the response I receive and I'm able to view my picks in JSON form:

airsenal_run_optimization --weeks_ahead 3
/Users/elliott.tong/Documents/AIrsenal/.venv/lib/python3.9/site-packages/urllib3/init.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020 warnings.warn( Running optimization with fpl_team_id 4704635 Login attempt 1/3... Failed Login attempt 2/3... Logged in successfully /Users/elliott.tong/Documents/AIrsenal/.venv/lib/python3.9/site-packages/airsenal/framework/optimization_utils.py:132: UserWarning: Failed to get current squad from API: Unable to access FPL API: 403 Client Error: Forbidden for url: https://fantasy.premierleague.com/api/my-team/4704635/

nbarlowATI commented 3 weeks ago

Hi @ElliottTDon (good team name BTW!! :) ).
Hmm.... I'm not sure why you're getting a 403 error there, especially when it says you have logged in successfully. I don't know, but I wonder if it could be related to the warning you see about urllib3 and OpenSSL - I don't see those warnings when I run that command. FWIW I'm using urllib3 version 1.26.11 - you could maybe try doing pip install urllib3==1.26.11 and see if that warning goes away, and maybe fixes the problem?

I don't know if it would really help debug this, since the error is clearly just that 403 error from the API, but if you want to explore interactively you could start a python session and do something like:

python
>>> from airsenal.framework.utils import *
>>> fetcher.get_current_picks()

(I guess you'll get the same error again...)