Now It works!. The solution was to add "format" to capsfilter. Previous caps filter string was:
caps = gst.Caps('video/x-raw-yuv,width=640,height=480,framerate=30/1')
and now it is:
caps = gst.Caps('video/x-raw-yuv,format=(fourcc)I420,width=640,height=480,framerate=30/1')
The problem was that my webcam default output pixel format was "YUYV" and the theoraenc element in my fileSink Bin not accepted this format, so adding format=(fourcc)I420
helped.
Still I don't know why the previous capsfilter string worked with gst-launch but I don't mind now.
Thanks for help