Git Product home page Git Product logo

Comments (7)

toddrob99 avatar toddrob99 commented on July 25, 2024

The statsapi.lookup_player() method uses the sports_players endpoint, which only seems to include active rosters. The only endpoint I've been able to find Bryce Harper (currently on IL) is team_roster with rosterType=allTime (statsapi.get("team_roster", {"teamId": 143, "rosterType": "allTime"})).

I could potentially update statsapi.lookup_player() to pull data from all the teams' allTime rosters, but there would be a significant speed reduction compared to the current method.

In any case, if you already have the personId, there's no reason to use statsapi.lookup_player(). Instead use the person endpoint (statsapi.get("person", {"personId": personId})).

from mlb-statsapi.

justintran12 avatar justintran12 commented on July 25, 2024

Is there a way to get a player's personId from their name? I think the lookup_player is the only way to do that correct? But I think am running into the same issue as OP when I try running lookup_player() for any player name, I get the following error:

File "C:...\statsapi\init.py", line 1227, in lookup_player
if str(lookup_value).lower() in str(v).lower():
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 10: ordinal not in range(128)

from mlb-statsapi.

toddrob99 avatar toddrob99 commented on July 25, 2024

Is there a way to get a player's personId from their name? I think the lookup_player is the only way to do that correct? But I think am running into the same issue as OP when I try running lookup_player() for any player name, I get the following error:

File "C:...\statsapi*init*.py", line 1227, in lookup_player if str(lookup_value).lower() in str(v).lower(): UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 10: ordinal not in range(128)

I think this is a different error. What code are you running that throws the error? @justintran12

from mlb-statsapi.

justintran12 avatar justintran12 commented on July 25, 2024

Is there a way to get a player's personId from their name? I think the lookup_player is the only way to do that correct? But I think am running into the same issue as OP when I try running lookup_player() for any player name, I get the following error:
File "C:...\statsapi*init*.py", line 1227, in lookup_player if str(lookup_value).lower() in str(v).lower(): UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 10: ordinal not in range(128)

I think this is a different error. What code are you running that throws the error? @justintran12

I get the error when I run statsapi.lookup_player('Harper') for example, I get the error for every name too.
Regarding my other question though, I am able to find player stats using a name with this example in your documentation:
statsapi.player_stats(next(x['id'] for x in statsapi.get('sports_players',{'season':2022,'gameType':'W'})['people'] if x['fullName']== player_name), 'hitting', 'career')

from mlb-statsapi.

toddrob99 avatar toddrob99 commented on July 25, 2024

I'm not sure why you're getting an error when you run lookup_player, because it works fine for me. It seems like whatever app you are running the code in has a unicode encoding issue, but it doesn't make sense because the u'\xe9' character it's complaining about is é, which does not appear in the result for the Harper lookup.

> python
Python 3.11.2 (tags/v3.11.2:878ead1, Feb  7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import statsapi
>>> statsapi.lookup_player('Harper')
[{'id': 547180, 'fullName': 'Bryce Harper', 'firstName': 'Bryce', 'lastName': 'Harper', 'primaryNumber': '3', 'currentTeam': {'id': 143}, 'primaryPosition': {'code': '10', 'abbreviation': 'DH'}, 'useName': 'Bryce', 'boxscoreName': 'Harper', 'nickName': 'Harp', 'mlbDebutDate': '2012-04-28', 'nameFirstLast': 'Bryce Harper', 'firstLastName': 'Bryce Harper', 'lastFirstName': 'Harper, Bryce', 'lastInitName': 'Harper, B', 'initLastName': 'B Harper', 'fullFMLName': 'Bryce Aron Max Harper', 'fullLFMName': 'Harper, Bryce Aron Max'}]
>>>

from mlb-statsapi.

justintran12 avatar justintran12 commented on July 25, 2024

I'm not sure why you're getting an error when you run lookup_player, because it works fine for me. It seems like whatever app you are running the code in has a unicode encoding issue, but it doesn't make sense because the u'\xe9' character it's complaining about is é, which does not appear in the result for the Harper lookup.

> python
Python 3.11.2 (tags/v3.11.2:878ead1, Feb  7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import statsapi
>>> statsapi.lookup_player('Harper')
[{'id': 547180, 'fullName': 'Bryce Harper', 'firstName': 'Bryce', 'lastName': 'Harper', 'primaryNumber': '3', 'currentTeam': {'id': 143}, 'primaryPosition': {'code': '10', 'abbreviation': 'DH'}, 'useName': 'Bryce', 'boxscoreName': 'Harper', 'nickName': 'Harp', 'mlbDebutDate': '2012-04-28', 'nameFirstLast': 'Bryce Harper', 'firstLastName': 'Bryce Harper', 'lastFirstName': 'Harper, Bryce', 'lastInitName': 'Harper, B', 'initLastName': 'B Harper', 'fullFMLName': 'Bryce Aron Max Harper', 'fullLFMName': 'Harper, Bryce Aron Max'}]
>>>

I just tested it again today and it works for me now... Both times I tested it, I did not use any other frameworks or apps. Perhaps it is an issue on MLB's API side? I noticed the structure of the data coming from MLB's API sometimes changes as the season goes on.

from mlb-statsapi.

toddrob99 avatar toddrob99 commented on July 25, 2024

Closing for now

from mlb-statsapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.