Python lacks the tail recursion optimizations which is common in functional languages like lisp. In Python, recursion is limited to 999 calls
1) You can change the recursion limit with sys.setrecursionlimit(n) until the maximum allowed for your platform:
2) You can try to convert the algorithm from recursive to iterative. If recursion depth is bigger than allowed by your platform, it is the only way to fix the problem.