Snap cursor to selected within a python script?
Set the location directly

There is no need to use the operator. 

What context are we looking at here? In object mode snaps to the average of selected objects origins, in edit mode the average of selected verts for mesh, bones for bones etc etc. When the global location vector (x, y, z) is known it's simply a matter of scene.cursor.location = (x, y, z) for 2.8x or scene.cursor_location in prior

eg 2.8x object mode example, moves cursor to average global location of selected objects.

import bpy
from mathutils import Vector

context = bpy.context
scene = context.scene 

obs = context.selected_objects
n = len(obs)
assert(n)

scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n