Error: Object 'Sphere.022' has no mesh data to be used for ray casting
You need to link the object to the scene and update it for ray casting to work.

import bpy, mathutils

obj = bpy.data.scenes[0].objects["Cube"].copy()
# Insert your new object in the scene
bpy.context.scene.objects.link(obj)
# Update scene
bpy.context.scene.update()

is_hit, hit_loc, hit_normal, index = obj.ray_cast(mathutils.Vector(), mathutils.Vector([1,1,1]))

print(is_hit, hit_loc, hit_normal, index)


Prints:

True &lt;Vector (1.0000, 1.0000, 1.0000)&gt; &lt;Vector (0.0000, 1.0000, 0.0000)&gt; 5


You might need to delete the object after your operation

bpy.context.scene.objects.unlink(obj)
bpy.data.objects.remove(obj)
del obj