Using knife_tool from python api
The knife tool is an interactive process that relies on the location of the mouse cursor and button clicks to perform it's task. This interactivity would make it hard to control from a python script.

To automatically edit a mesh through python you want to look at the bmesh module which is the underlying foundation to all mesh editing operations.

The issue with incorrect context indicates that the operator only works while the 3dview is active.