cycles_preferences.get_devices() is returning
None. You want
cycles_preferences.devices instead. But that may fail with a different error if you have more than two entries in
devices. On my system, that's currently returning 3 devices.
If you try
get_devices and a Tab for completion in the Python console you get this:
# Deprecated: use refresh_devices instead.
But further investigation says that just updates the device list. So your code should probably be
preferences = bpy.context.preferences
cycles_preferences = preferences.addons["cycles"].preferences
cuda_devices = cycles_preferences.devices
opencl_devices = cycles_preferences.devices