yahoo_fantasy_api icon indicating copy to clipboard operation
yahoo_fantasy_api copied to clipboard

Can't get player details of players whose names contain an apostrophe (only NBA tested)

Open ntsirakis opened this issue 5 years ago • 2 comments

Example: league.player_details("De'Aaron Fox") throws the following:

  File "[trunc]/yahoo_fantasy_api/yhandler.py", line 176, in get_player_raw
    return self.get("league/{}/{}".format(league_id, player_stat_uri))
  File [trunc]/yahoo_fantasy_api/yhandler.py", line 25, in get
    raise RuntimeError(response.content)
RuntimeError: b'<?xml version="1.0" encoding="UTF-8"?>\n<error xml:lang="en-us" yahoo:uri="http://fantasysports.yahooapis.com/fantasy/v2/league/395.l.36985/players;search=D&amp;#39;Angelo%20Russell/stats?format=json" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" xmlns="http://www.yahooapis.com/v1/base.rng">\n <description>invalid param search (was modified by yiv_get_stripped )</description>\n <detail/>\n</error>'

Removing the apostrophe (league.player_details("DeAaron Fox")) throws the following:

  File "[trunc]/yahoo_fantasy_api/league.py", line 455, in player_details
    for category in player['0']['player']:
TypeError: list indices must be integers or slices, not str

Funnily enough you can get the data by removing the entire chunk before the apostrophe, so in this case, league.player_details("Aaron Fox")

Version: 1.8.1. Briefly checked commits since then and didn't see anything that would fix this.

ntsirakis avatar Feb 13 '20 00:02 ntsirakis

It kind of seems like a limitation with the yahoo REST API we're using. I was not able to pass in a name with an apostrophe, even after doing URL encoding (i.e. %20).

In 2.0.1, when the search does not find any players, I now return an empty list rather than the TypeError exception you were seeing.

spilchen avatar Feb 15 '20 03:02 spilchen

Fair enough, that's a shame. I'll continue with the workaround I have now. Thanks for checking anyway!

ntsirakis avatar Feb 16 '20 00:02 ntsirakis