Thank you @ptrblck for providing a solution to this problem.  I was facing the same problem, luckily I found this post. But when I run this code I face another Error. Can you please help me to solve it.
TypeError: endswith first arg must be str or a tuple of str, not list