The first formula uses k as the number of independent variables, but it does not include the intercept. The second formula uses k + 1, meaning it includes the intercept in the count.
The first formula is not wrong but it is using a different definition for k. But since Python includes the intercept, you need to use the second formula to match it.