Rotate an object around an axis using python script
If you don't want to manipulate matrix_world you have to check the rotation_mode of the object first and set the corresponding value accordingly.

import bpy
import math
import mathutils

obj = bpy.context.active_object
eul = mathutils.Euler((0.0, math.radians(45.0), 0.0), 'XYZ')

if obj.rotation_mode == "QUATERNION":
    obj.rotation_quaternion = eul.to_quaternion()
elif obj.rotation_mode == "AXIS_ANGLE":
    q = eul.to_quaternion()
    obj.rotation_axis_angle[0]  = q.angle
    obj.rotation_axis_angle[1:] = q.axis
else:
    obj.rotation_euler = eul if eul.order == obj.rotation_mode else(
        eul.to_quaternion().to_euler(obj.rotation_mode))