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
  How to access parent object attribute Pavel_47 2 197 Nov-19-2021, 09:36 PM
Last Post: deanhystad
  Getting 'NoneType' object has no attribute 'find' error when WebScraping with BS Franky77 2 535 Aug-17-2021, 05:24 PM
Last Post: Franky77
  Message='int' object is not subscriptable DanielCook 4 541 Aug-10-2021, 05:21 PM
Last Post: deanhystad
  AttributeError: 'DataFrame' object has no attribute 'Articles' Anldra12 5 2,227 Jun-17-2021, 04:54 PM
Last Post: Larz60+
  AttributeError: 'Node' object has no attribute 'insert' Anldra12 4 1,752 May-11-2021, 10:12 AM
Last Post: Anldra12
  AttributeError: module 'string' has no attribute 'uppercase' Anldra12 10 2,878 Apr-23-2021, 05:30 PM
Last Post: ibreeden
  AttributeError: 'tuple' object has no attribute 'format' Anldra12 7 7,823 Apr-13-2021, 07:45 AM
Last Post: Anldra12
Lightbulb 'str' object has no attribute 'to_csv' brunolelli 3 4,353 Mar-25-2021, 06:40 AM
Last Post: ndc85430
  AttributeError class object has no attribute list object scttfnch 5 1,086 Feb-24-2021, 10:03 PM
Last Post: scttfnch
  AttributeError: 'NoneType' object has no attribute 'next' loves 2 3,323 Dec-15-2020, 11:30 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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