outside-edge / python-espncricinfo

Python wrapper for the ESPNCricInfo JSON API
MIT License
146 stars 64 forks source link

IndexError: list index out of range in player.py #24

Closed Ehsan1997 closed 6 years ago

Ehsan1997 commented 6 years ago

Here's the traceback, as you can see the problem arises when trying to get player data with id '10125'. Probably some unhandled exception.

Traceback (most recent call last):
  File "C:/Users/ehsan/PycharmProjects/ScrapPSLData/test_player.py", line 2, in <module>
    p = Player('10125')
  File "C:\Users\ehsan\AppData\Roaming\Python\Python36\site-packages\espncricinfo\player.py", line 34, in __init__
    self.recent_matches = self._recent_matches()
  File "C:\Users\ehsan\AppData\Roaming\Python\Python36\site-packages\espncricinfo\player.py", line 223, in _recent_matches
    table = self.parsed_html.findAll('table', class_='engineTable')[3]
IndexError: list index out of range
dwillis commented 6 years ago

@Ehsan1997 just tested this out with the latest version of the library and didn't run into that error.

Ehsan1997 commented 6 years ago

Sorry, you are right @dwillis the new version has it fixed. I thought I updated but probably missed the new version.

Ehsan1997 commented 6 years ago

I was also confused about player_id and object_id, it seems to create a player object object_id is required. Also there is some problem for this id (8180).

Traceback (most recent call last):
  File "C:/Users/ehsan/PycharmProjects/ScrapPSLData/CreateCSV_AdvStats.py", line 9, in <module>
    p = Player(8180)
  File "C:\Users\ehsan\AppData\Local\Programs\Python\Python36\lib\site-packages\espncricinfo\player.py", line 34, in __init__
    self.first_class_debut = self._first_class_debut()
  File "C:\Users\ehsan\AppData\Local\Programs\Python\Python36\lib\site-packages\espncricinfo\player.py", line 173, in _first_class_debut
    url = 'http://www.espncricinfo.com'+first_class_debut.find('a')['href']
TypeError: 'NoneType' object is not subscriptable

There is probably no 'a' tag in first_class_debut.

dwillis commented 6 years ago

Good catch. object_id is what the cricinfo match JSON calls the player_id, so we need to use that in places. The debuts code is probably not long for this world because there is a way to get that that doesn't rely on HTML parsing, instead using more JSON. But in the meantime I'll handle this error.

dwillis commented 6 years ago

Just pushed a fix for https://github.com/dwillis/python-espncricinfo/issues/24#issuecomment-410534291