The problem is that 'QgsVectorLayer' objects have not attribute 'renderer'. This kind of method is for raster layers. If you want to change the transparency of QgsVectorLayer objects you have to use the method: 'setLayerTransparency(int)'; located in QgsVectorLayer class.
Next code works for these kind of objects:
mc=iface.mapCanvas()
layers=[]
n = mc.layerCount()
for i in range(n):
layers.append(mc.layer(i))
for layer in layers:
if layer.type() == 0: #QgsVectorLayer
layer.setLayerTransparency(95)
layer.triggerRepaint()
else:
layer.renderer().setOpacity(0.5)
layer.triggerRepaint()
I tested it in QGIS. See next images (raster layer has a different projection but the transparency was also assigned):