Updating generic.py error message

This is my first attempt at a PR. I just made a little change to allow an error message. Would appreciate some feedback. 
Based on https://github.com/pydata/pandas/issues/8015
Just wondering, is there no other way that an AttributeError could be triggered here? 
If so, it is maybe better to explicitely check if by and level are None and raise in that case.