Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ElliottTDon opened this issue Aug 20, 2024 · 8 comments

Comments

@ElliottTDon
Copy link

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
Copy link
Member

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
Copy link
Author

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: urllib3/urllib3#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
Copy link
Member

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...)

@Iain-SF
Copy link

Iain-SF commented Sep 14, 2024

I'm running in to this issue also.

Running optimization with fpl_team_id 1487656
Login attempt 1/3... Failed
Login attempt 2/3... Logged in successfully
/home/iain/miniconda3/envs/airsenalenv/lib/python3.12/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/1487656/
Using DB instead, which may be out of date.
warnings.warn(
Getting starting squad for 1487656
/home/iain/miniconda3/envs/airsenalenv/lib/python3.12/site-packages/airsenal/framework/utils.py:431: UserWarning: Failed to get actual free transfers from a logged in API:
Unable to access FPL API: 403 Client Error: Forbidden for url: https://fantasy.premierleague.com/api/my-team/1487656/
Will try to estimate it from the API without logging in, which will not include any transfers used in the current gameweek.

Any help would be appreciated.

@jack89roberts
Copy link
Contributor

jack89roberts commented Sep 15, 2024

Hi @Iain-SF , do you still get the error today and is it the same if you run airsenal_run_pipeline (if you're not already)?

@Iain-SF
Copy link

Iain-SF commented Sep 19, 2024

Hey Jack, Yeah still getting the error (when running airsenal_run_pipeline too). I'll set up from fresh again at the weekend and report back.

@jack89roberts
Copy link
Contributor

jack89roberts commented Sep 23, 2024

It seems to run ok for me with your team ID, e.g. here are the outputs of an optimization (it won't reflect any transfers you've already made this gameweek, if any, as you need to login to get transfers since the last deadline):

Strategy for Team ID: 1487656
Baseline score: 157.728495821423
Best score: 167.5136329015096
 ===============================================
 ========= Optimum strategy ====================
 ===============================================

 =========== Gameweek 6 ================

Chips played:  None

Players in:			Players out:
-----------			------------
Jarrod Bowen			Diogo Teixeira da Silva

 =========== Gameweek 7 ================

Chips played:  None

Players in:			Players out:
-----------			------------
Mohammed Kudus			Morgan Gibbs-White

 =========== Gameweek 8 ================

Chips played:  None

Players in:			Players out:
-----------			------------
James Maddison			Kevin De Bruyne

==========================
 Total score: 167

Getting starting squad for 1487656

=== starting 11 ===


== GK ==

David Raya Martin (ARS)

== DEF ==

Pedro Porro (TOT)
Joško Gvardiol (MCI)
Manuel Akanji (MCI)
Trent Alexander-Arnold (LIV)(VC)

== MID ==

Kevin De Bruyne (MCI)
Mohamed Salah (LIV)(C)
Eberechi Eze (CRY)
Jarrod Bowen (WHU)

== FWD ==

Danny Welbeck (BHA)
Jamie Vardy (LEI)

=== subs ===

Guglielmo Vicario (TOT)
Rodrigo Muniz Carvalho (FUL)
Trevoh Chalobah (CHE)
Morgan Gibbs-White (NFO)

As well as pulling the latest version and re-installing, try running airsenal_run_pipeline --clean - that causes the whole database to be deleted and re-created, which might fix things if you have something weird saved in your current one.

If none of that works it's a bug specific to your system, so trickier to debug, but following some of the steps Nick wrote above in response to the original issue might help point us in the right direction.

EDIT: Also, although you get login failed errors, does the optimisation continue to run successfully after that or does it completely crash/fail?

@Iain-SF
Copy link

Iain-SF commented Sep 23, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants