How to find out why "context is incorrect"? I have been trying to write my first addon for Blender over the last couple of days. One error I came across quite often is the context is incorrect error for an operation of bpy.ops.

I learned that one can ask the poll function of an operator if the context is correct, but this does not tell why the context is correct/incorrect. What would be the best way to figure that out? Only way I could think of is to look into the code of the poll function. If that is the best way, what is the fastest way to find the appropriate piece of code?
You can find out (part of) the context you are in by:

cont = bpy.context.area.type
print(str(cont))


This in itself will help you determine where you are (contextually speaking).
Determining where you need to be is another story.  Each operation that you
do in Blender requires that you be in the correct context.  The way I think
of context is, what window (context) does  the operation occur in when you 
do the action by clicking with the mouse?  You also may need to refer to the API
or other info, but one thing I found to help is knowing what contexts exist!

And easy way to find that out is:

bpy.context.area.type = '?'


This throws a useful error:


  TypeError: bpy_struct: item.attr = val: enum "?" not found in ('VIEW_3D', 'TIMELINE', 'GRAPH_EDITOR', 'DOPESHEET_EDITOR', 'NLA_EDITOR', 'IMAGE_EDITOR', 'SEQUENCE_EDITOR', 'CLIP_EDITOR', 'TEXT_EDITOR', 'NODE_EDITOR', 'LOGIC_EDITOR', 'PROPERTIES', 'OUTLINER', 'USER)


Well, there are your context types . . .

I don't know if that has successfully answered your question, because I do not write
plugins, yet, but it might has something that helps get you past the current issue in it.