python: fix some bugs