Python Forum
AttributeError: 'Message' object has no attribute 'split'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: 'Message' object has no attribute 'split'
I just don't know how to describe anything, because I'm too confused, But all I know is it's supposed to make it into a string but it didn't work. Here is the server code:
god bless buran for this code <3
import json
import socket
import os
from _thread import *
from pathlib import Path

from cryptotools import RSA

UUID = None
lastClient = False
key, pkey = RSA.generate_keypair(1024)
ServerSideSocket = socket.socket()
host = ''
port = 2004
ThreadCount = 0
response = "NotExists"
    ServerSideSocket.bind((host, port))
except socket.error as e:

print('Socket is listening..')

def multi_threaded_client(connection):
    global UUID, lastClient, ThreadCount, key, pkey, response
    while True:
            data = connection.recv(1024).decode()
            if data != "":
                print(f'Decoded raw data: {data}')
            if data[0:4] == "UUID":  # PKEY
                key, pkey = RSA.generate_keypair(1024)
                Content = data.split("UUID")[1]
                UUID = json.loads(Content)
                msg = json.dumps(pkey)
                if data == "quit":
                    ThreadCount = ThreadCount - 1
                data = RSA.Message.from_hex(data)
                data = data.str()
                if data[0:4] == "USER":  # USER
                    User = data.split("USER")[1]
                    Users = Path("C:/Users/####/PycharmProjects/pythonProject2/logins.txt")
                    Users ='r').read().splitlines()
                    for line in Users:
                        if not any(a in line for a in User):
                            response = line
                    response = RSA.Message.from_str(response)
                if data[0:4] == "PSWD":  # PSWD
                    Password = data.split("PSWD")[1]
                    PSWD = response.split(":")[1]
                    response = 'Correct' if PSWD == Password else 'Incorrect'
                    message = RSA.Message.from_str(response)
        except KeyboardInterrupt:

while True:
    if lastClient:
        Client, address = ServerSideSocket.accept()
    except KeyboardInterrupt:
    print('Connected to: ' + address[0] + ':' + str(address[1]))
    start_new_thread(multi_threaded_client, (Client,))
    ThreadCount += 1
    print('Thread Number: ' + str(ThreadCount))
I know I know, the error speaks for itself, but here is the thing, I already converted the Message object to str
Client (just in case):
import atexit
import socket
import json
from time import sleep
import _thread
from cryptotools import RSA
import sys
sys.stdout.write("\rSending public key")
msg = f'UUID{json.dumps(public)}'
sys.stdout.write("\rWaiting for server public key to be recieved.")
serverkey = json.loads(s.recv(1024).decode())
while True:
    sys.stdout.write("\rPlease Enter your username:                  \n")
    user = "USER" + input()
    user = RSA.Message.from_str(user)
    s.sendall(user.hex().replace(' ', '').encode())
    Recieved = s.recv(1024).decode()
    Recieved = RSA.Message.from_hex(Recieved)
    Recieved = Recieved.str()
    if Recieved != "NotExists":
        R = Recieved.split(":")[2].split(",")
        sys.stdout.write("\rPlease Enter A Password:                     \n")
        new_pass = input()
        new_pass = f'PSWD{new_pass}'
        msg = RSA.Message.from_str(new_pass)
        s.sendall(msg.hex().replace(' ', '').encode())
        rawdata = s.recv(1024).decode()
        recieved = RSA.Message.from_hex(rawdata)
        if str(recieved).split("b'")[1].split("'")[0].find("Correct") != -1:
            loggedin = True
            loggedin = False
        if loggedin:
            sys.stdout.write("Correct login.")
            for item in contacts:
                if item == "" and counter == 0:
                    sys.stdout.write("no blins :(")
                sys.stdout.write(item + "\n")
                counter = counter + 1
        sys.stdout.write("Wrong Username! Try again")
Traceback (most recent call last): File "C:\Users\####\PycharmProjects\pythonProject2\", line 58, in multi_threaded_client Password = data.split("PSWD")[1] AttributeError: 'Message' object has no attribute 'split'
Hm. That is strange. I would expect that you should get error on this line

PSWD = response.split(":")[1]
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

idk how to delete messages.
Attribute errors in Python are generally raised when you try to access or call an attribute that a particular object type doesn't possess. The string.split function exists in Python 2.x but not in Python 3.x, where it is only available as an instance method of the str class.

It's simply because there is no attribute with the name you called, for that Object. This means that you got the error when the "module" does not contain the method you are calling. But it is evident that the method is there, which leads to believe that may be the method was added by you in the source code after you had already imported the file (module). Or, some times packages get deprecated and they rename some functions. If that is true, then you may want to exit and reimport the module once again to be able to access the new method .
You can do it in another way to reimport the module with changes without having to exit the interpreter is to do the following:


If you are using python 3.2 or 3.3 you should:

Quote:import imp

If running Python 3.4 and up, do import importlib, then do:

Quote:import importlib

The importlib.reload() method reload a previously imported module. The argument must be a module object, so it must
Gribouillis write Dec-14-2021, 07:36 AM:
Please don't necropost with sole purpose to advertise your site.

Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: 'NoneType' object has no attribute 'group' MaartenRo 3 185 Jan-02-2022, 09:53 AM
Last Post: snippsat
  AttributeError: 'NoneType' object has no attribute 'group' MaartenRo 3 156 Jan-01-2022, 04:16 PM
Last Post: MaartenRo
  How to access parent object attribute Pavel_47 2 373 Nov-19-2021, 09:36 PM
Last Post: deanhystad
  Getting 'NoneType' object has no attribute 'find' error when WebScraping with BS Franky77 2 997 Aug-17-2021, 05:24 PM
Last Post: Franky77
  Message='int' object is not subscriptable DanielCook 4 713 Aug-10-2021, 05:21 PM
Last Post: deanhystad
  AttributeError: 'DataFrame' object has no attribute 'Articles' Anldra12 5 2,623 Jun-17-2021, 04:54 PM
Last Post: Larz60+
  AttributeError: 'Node' object has no attribute 'insert' Anldra12 4 2,109 May-11-2021, 10:12 AM
Last Post: Anldra12
  AttributeError: module 'string' has no attribute 'uppercase' Anldra12 10 3,417 Apr-23-2021, 05:30 PM
Last Post: ibreeden
  AttributeError: 'tuple' object has no attribute 'format' Anldra12 7 9,099 Apr-13-2021, 07:45 AM
Last Post: Anldra12
Lightbulb 'str' object has no attribute 'to_csv' brunolelli 3 5,095 Mar-25-2021, 06:40 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020