Python 2.8 - updating code sample from v. 2.63 (image rendering and saving)
The line to set the viewport shading needs to change from

area.spaces[0].viewport_shade = 'RENDERED'


to

area.spaces[0].shading.type = 'RENDERED'


since Blender 2.8's API has replaced viewport_shade. Here you can find the documentation of the Area, AreaSpaces, SpaceView3D (if the space is of type 'VIEW_3D') and View3DShading.

Although I'm wondering why you'd want to set the viewport shading if you intend to actually render the scene. In case this really is what you want I'd suggest getting the active space, which will be the one currently displayed.

for area in bpy.context.screen.areas: 
    if area.type == 'VIEW_3D':
        space = area.spaces.active
        space.shading.type = 'RENDERED'