Comments (7)
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.
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.
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.
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.
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.
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 theHarper
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.
Closing for now
from mlb-statsapi.
Related Issues (20)
- team stats HOT 1
- Missing documentation? HOT 2
- Standings_data division parameter should accept divisionId instead of only abbreviation HOT 5
- Past 7 Day stats for player id HOT 1
- Get request for 'team_stats' returning 404 HOT 1
- Return line score when using schedule end point HOT 2
- dataclass() got an unexpected keyword argument 'kw_only' HOT 2
- TypeError: Teamrecords.__init__() got an unexpected keyword argument 'eliminationnumbersport' HOT 2
- Determining a list of teams that a player played on HOT 1
- SSL: SSLV3_ALERT_HANDSHAKE_FAILURE HOT 1
- game_contextMetrics 404 Not Found for url HOT 6
- Unexpected behavior in lookup_player() when season is not specified HOT 1
- Incorrect seasons endpoint documentation HOT 2
- boxscore_data function returns incorrect and incomplete batting notes. HOT 2
- Player Stats Error HOT 10
- Typos HOT 5
- Get Team Mark HOT 2
- Extra Games in Schedule HOT 2
- Normalize diacritics in player lookup HOT 6
- The divisions endpoint allows 'season' as an optional endpoint.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mlb-statsapi.