TypeError:'builtin_function_or_method'对象没有属性'__getitem__'

时间:2013-10-28 18:51:54

标签: python ip-address typeerror hostname

我在尝试获取用户的主机名时遇到了奇怪的TypeError。

def getHostName(tfm, username):
    found = False
    for room in tfm.rooms.values():
            for playerCode, client in room.clients.items():
                    if client.username == username:
                            found = socket.gethostbyaddr(socket.gethostname())[0]
                            break
    return found

这就是我以前获取主机名的原因,而这就是它的错误。

def getIPaddress(tfm, username):
    found = False
    for room in tfm.rooms.values():
            for playerCode, client in room.clients.items():
                    if client.username == username:
                            found = client.address[0]
                            break
    return found

这就是我成功获得IP地址的原因。

Traceback (most recent call last):
  File "Wesley.py", line 544, in found_terminator
    tfm.parsePacket(packet, MDT, Size)
  File "Wesley.py", line 760, in parsePacket
    tfm.parseDataUTF(packet[2:struct.unpack('!h', packet[:2])[0]+2])
  File "Wesley.py", line 1063, in parseDataUTF
    Commands(tfm, values[0], values)
  File "/root/Server/Commands.py", line 2543, in ParseCommand
    hostname = tfm.server.getHostName(username)
  File "Wesley.py", line 5757, in getHostName
    found = socket.gethostbyaddr(socket.gethostname())[0]
TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'

我使用命令指定用户名。

0 个答案:

没有答案