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

Private leagues #28

Open
tonycpsu opened this issue Aug 4, 2017 · 16 comments
Open

Private leagues #28

tonycpsu opened this issue Aug 4, 2017 · 16 comments

Comments

@tonycpsu
Copy link

tonycpsu commented Aug 4, 2017

Hi, this is an interesting project. Is there any chance of supporting private leagues using stored credentials in the future via OAuth or whatever the ESPN backend is using?

@irish1986
Copy link

I would be very interested in this feature too.

@segfaultmagnet
Copy link
Contributor

If you log in via your browser and look at the cookies stored, you should see two named 'espn_s2' and 'SWID'. If you pass those with the GET request in League._fetch_league() it will work:

def _fetch_league(self):
  params = {
    'leagueId': self.league_id,
    'seasonId': self.year
  }
  cookes = {
    'espn_s2': ... ,
    'SWID': ...
  }
  r = requests.get('%sleagueSettings' % (self.ENDPOINT, ), params=params, cookies=cookies)
  self.status = r.status_code
  data = r.json()
  
  ...

@rbarton65
Copy link
Owner

I'll be closing this in the next patch. Thank you @segfaultmagnet!

@CMorton737
Copy link

CMorton737 commented Sep 15, 2017

Hmm, so have we verified that this works? If so, what method did you guys use find the espn_s2 and SWID, and what format are they in. Do you submit the SWID with braces or without?

Here is what my cookies looked like:
espn_s2 = 'AEBgTXbacKBU5zbrNX%2BPGXBK%2Bwxxm6TvJpxIUWQqKwxnjK6sbPhEufM0%2FJj8taBNGKafQb10YQqo6Ffqn2%2F36Nq08Cpyx1yvNvlZCq8xURq5KHx3zqdC5yPeIyJcfoqa5aTAb5FfuVZgh4vOC8Bw0dIyir2EynkvqyqsaMnlX2ZZDIaoHMg9s%2BvHUCd6gwg06Rw8ILpVRPc06Q0IUlEFPBDrEn%2B%2BjE91zvDglmS40dJ6nZK3cRS9sOBY%2B05G%2Fy%2F4gxTlckvtVZzBIG0zgz6yc%2Bs'
swid = '{C74679B2-D38S-FHD9-8679-B2D3827FE992}'
Not real credentials

@blattus
Copy link

blattus commented Sep 15, 2017

This works for me -- you'll need to grab the latest master branch from github instead of using the pip install since I don't think the change is in a release yet.

Those credentials look right to me as well, I did include the braces for the SWID and that worked.

The auth will look something like this:

league = League(league_id,year,espn_s2,swid)

@CMorton737
Copy link

Right. How did you find you espn_s2?

@blattus
Copy link

blattus commented Sep 15, 2017

@CMorton737 I found it by inspecting the league homepage in Chrome, going to the Application tab, and looking for espn_s2 under Cookies

@segfaultmagnet
Copy link
Contributor

segfaultmagnet commented Sep 15, 2017

You can find them by logging in through your browser and looking at cookies for espn.com after you've logged in. A better method would be to use the client that fgblomqvist came up with.

edit: More specifically, they are cookies for games.espn.com.

@mpcen
Copy link

mpcen commented Oct 20, 2017

How are you supposed to grab the cookie from a private league on the league home page if the league is private to begin with? Can a cookie from any league work?

@CMorton737
Copy link

CMorton737 commented Oct 20, 2017

It needs to be your account. Use your ESPN log-in credentials to sign in to your account, and only then will you be able to access the espn_s2 and swid cookies. These cookies are unique to your account, and determine what private leagues on ESPN you have access to (only leagues that are associated with your email address/ESPN account)

If your account does not have access to a private league through the web UI, then you cannot obtain the cookies required to access it programmatically.

@paulavellino
Copy link

I think I'm following this to a T. However, when I type league = League(league_id, year, espn_s2, swid) I receive the following error
Traceback (most recent call last):
File "", line 1, in
TypeError: init() takes 3 positional arguments but 5 were given
I got my league_id and year from the url in my league home page. I got the cookies from the chrome browser cookie store. any clues that can help me?

@therrell
Copy link

I think I'm following this to a T. However, when I type league = League(league_id, year, espn_s2, swid) I receive the following error
Traceback (most recent call last):
File "", line 1, in
TypeError: init() takes 3 positional arguments but 5 were given
I got my league_id and year from the url in my league home page. I got the cookies from the chrome browser cookie store. any clues that can help me?

I'm also getting this. Did you figure it out?

@DFrancis84
Copy link

I am still having issues getting it to work for private leagues...

  File "<stdin>", line 1, in <module>
  File "/home/devinfrancis/go/src/github.com/espnff/espnff/league.py", line 22, in __init__
    self._fetch_league()
  File "/home/devinfrancis/go/src/github.com/espnff/espnff/league.py", line 42, in _fetch_league
    data = r.json()
  File "/home/devinfrancis/.local/lib/python3.6/site-packages/requests/models.py", line 892, in json
    return complexjson.loads(self.text, **kwargs)
  File "/home/devinfrancis/anaconda3/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/home/devinfrancis/anaconda3/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/home/devinfrancis/anaconda3/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 2 (char 2)

current league.py

    '''Creates a League instance for Public ESPN league'''
    def __init__(self, league_id, year, espn_s2=None, swid=None):
        self.league_id = league_id
        self.year = year
        self.ENDPOINT = "http://games.espn.com/ffl/api/v2/"
        self.teams = []
        self.espn_s2 = espn_s2
        self.swid = swid
        self._fetch_league()

    def __repr__(self):
        return 'League(%s, %s)' % (self.league_id, self.year, )

    def _fetch_league(self):
        params = {
            'leagueId': self.league_id,
            'seasonId': self.year
        }

        cookies = None
        if self.espn_s2 and self.swid:
            cookies = {
                'espn_s2': self.espn_s2,
                'SWID':self.swid
            }

        r = requests.get('%sleagueSettings' % (self.ENDPOINT, ), params=params, cookies=cookies)
        self.status = r.status_code
        data = r.json()

        if self.status == 401:
            raise PrivateLeagueException(data['error'][0]['message'])

        elif self.status == 404:
            raise InvalidLeagueException(data['error'][0]['message'])

        elif self.status != 200:
            raise UnknownLeagueException('Unknown %s Error' % self.status)

        self._fetch_teams(data)
        self._fetch_settings(data)

@CMorton737
Copy link

Can you post a scrubbed example of the swid and s2 tokens youre using?

@DFrancis84
Copy link

Can you post a scrubbed example of the swid and s2 tokens youre using?

swid = "{64052795-34DE-####-####-342A1BE73B81}"
espn_s2 = "AECby4L96%2Fih5lhWN39Fvec9mqVc4sx1VHnj%2FMyjcENvxoVXd1GYqkmEqXPRHTwLl%2BA%2FsqYynHuSESGURUV81Cv0W%2BuVOhwpxNblrJoIn%2F8dDZ9d9nEoxcs%2BuphOdWUICNrffnSeIcXc75zp%2Bvoh06JEA%2B7swJ4%2FzkENU%2Bnn6%2Fqf12XlsOGI7q7zOcYSg%3D%3D"

Those are what I am entering.. Obviously I removed characters for security purposes

@DFrancis84
Copy link

Can you post a scrubbed example of the swid and s2 tokens youre using?

Did you get a change to look at it and see what's going on?

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

10 participants