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'
#1
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 = '192.168.1.14'
port = 2004
ThreadCount = 0
response = "NotExists"
try:
    ServerSideSocket.bind((host, port))
except socket.error as e:
    print(str(e))

print('Socket is listening..')
ServerSideSocket.listen(5)


def multi_threaded_client(connection):
    global UUID, lastClient, ThreadCount, key, pkey, response
    while True:
        try:
            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)
                connection.sendall(msg.encode())
            else:
                if data == "quit":
                    ThreadCount = ThreadCount - 1
                    break
                data = RSA.Message.from_hex(data)
                data.decrypt(key)
                data = data.str()
                if data[0:4] == "USER":  # USER
                    User = data.split("USER")[1]
                    Users = Path("C:/Users/####/PycharmProjects/pythonProject2/logins.txt")
                    Users = Users.open('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)
                    response.encrypt(UUID)
                    connection.sendall(response.hex().encode())
                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)
                    message.encrypt(UUID)
                    connection.sendall(message.hex().encode())
        except KeyboardInterrupt:
            print("Exiting")


while True:
    if lastClient:
        break
    try:
        Client, address = ServerSideSocket.accept()
    except KeyboardInterrupt:
        exit(0)
    print('Connected to: ' + address[0] + ':' + str(address[1]))
    start_new_thread(multi_threaded_client, (Client,))
    ThreadCount += 1
    print('Thread Number: ' + str(ThreadCount))
ServerSideSocket.close()
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)}'
s.sendall(msg.encode())
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)
    user.encrypt(serverkey)
    s.sendall(user.hex().replace(' ', '').encode())
    Recieved = s.recv(1024).decode()
    Recieved = RSA.Message.from_hex(Recieved)
    Recieved.decrypt(private)
    Recieved = Recieved.str()
    print(Recieved)
    if Recieved != "NotExists":
        R = Recieved.split(":")[2].split(",")
        contacts.extend(R)
        sys.stdout.seek(0)
        sys.stdout.write("\rPlease Enter A Password:                     \n")
        new_pass = input()
        new_pass = f'PSWD{new_pass}'
        msg = RSA.Message.from_str(new_pass)
        msg.encrypt(serverkey)
        s.sendall(msg.hex().replace(' ', '').encode())
        rawdata = s.recv(1024).decode()
        recieved = RSA.Message.from_hex(rawdata)
        recieved.decrypt(private)
        if str(recieved).split("b'")[1].split("'")[0].find("Correct") != -1:
            loggedin = True
        else:
            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
    else:
        sys.stdout.write("Wrong Username! Try again")
        continue
Error:
Traceback (most recent call last): File "C:\Users\####\PycharmProjects\pythonProject2\server.py", line 58, in multi_threaded_client Password = data.split("PSWD")[1] AttributeError: 'Message' object has no attribute 'split'
Reply
#2
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

Reply
#3
idk how to delete messages.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 721 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,533 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,385 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  Parallel processing - AttributeError: Can't get attribute 'sktimekmeans' Mohana1983 1 704 Jun-22-2023, 02:33 AM
Last Post: woooee
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 3,668 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 687 Jun-14-2023, 12:37 PM
Last Post: deanhystad
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,215 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,302 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  WebDriver' object has no attribute 'find_element_by_css_selector rickadams 3 5,780 Sep-19-2022, 06:11 PM
Last Post: Larz60+
  'dict_items' object has no attribute 'sort' Calli 6 4,352 Jul-29-2022, 09:19 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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