Erm, I have ready-to-use code, and I’m sure it really works, but I get the following error:
TypeError: descriptor ‘split’ requires a ‘str’ object but received a
‘unicode’
That’s the whole def:
def assemblePacket(self, type):
ipSplit = str.split(self.serverVars[0], '.')
packet = 'SAMP'
packet += chr(int(ipSplit[0]))
packet += chr(int(ipSplit[1]))
packet += chr(int(ipSplit[2]))
packet += chr(int(ipSplit[3]))
packet += chr(self.serverVars[1] & 0xFF)
packet += chr(self.serverVars[1] >> 8 & 0xFF)
packet += type
return packet
And here is the problem:
ipSplit = str.split(self.serverVars[0], '.')
I’m sure it’s not because of the code, I’ve tried it before (the same script) and it worked. No idea why it doesn’t now.And this “unicode” makes me think I have to change “str.split”, but hmmm. Waiting for opinions 🙂
The problem is that
str.splitis a method of thestrclass, but is being called for an object of theunicodeclass. Call the method directly withipSplit = self.serverVars[0].split('.')to have it work for anything (includingstrandunicode) with asplitmethod.