Just a guess, but if a device does not have a name assigned, many API calls will return an object called None instead of the name. None is not a string, it's type is NoneType.
I'd think this is high probability if you are using a call that returns inventory as unused devices will not have a name.
The same type of thing can happen with other calls/elements, you usually find out the hard way that an API call can do this!
In dashboard UI, it defaults missing names to the device MAC address, but the API generally does not do this, if there is no name, you get None.
So in your code, the error is because None is not acceptable.
I've not tested, but try this instead, it might work...
SortedListOfDevices = sorted(response, key=lambda d: d['mac'] if d['name'] is None else d['name'])