Python Forum
Can't strip extra characters from Data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't strip extra characters from Data
#8
I've managed to figure out both how to clean up the data and strip off the extra characters as well as forward the info to another computer. Now I'm stuck as I'm not sure if I've got the right object to communicate with the other computer. It seems that sockets only transmit in binary and after stripping the information, I am unable to send the re-formatted in text format to the other computer. It will only go in binary with the extra characters and I can also not send a carriage return so that the data sent comes in on a new line with each send? Since I'm unfamiliar with Python and only have experience with older languages, is there a way to do this or do I have to utilize a different language?

I'll include the code where I'm at at this point so you can see what I've done and maybe someone will have a solution.

Thanks in advance!

import socket, sys

host = ''               
port = 65432
socksize = 19

s2 = socket.socket()
s2.connect(('192.168.1.228',65431))

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(1)
print("Now listening...")

def remove_punc(s):
    from_ = 'GET/&'
    to = '     '
    translation = str.maketrans(from_,to)
    new = s.translate(translation)
    return ' '.join(new.split())


while True:
    conn, addr = s.accept()
    data = conn.recv(socksize)
    if not data:             
        x=1
    else:
        s2.send(data)
        #s2.send(0D0A HEX)
        data = data.decode('utf-8')
        print(data)
        test = (remove_punc(data))
        print(test)
        #s2.send(test)
Reply


Messages In This Thread
RE: Can't strip extra characters from Data - by Canflyguy - Jan-10-2022, 02:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  extract only text strip byte array Pir8Radio 7 3,030 Nov-29-2022, 10:24 PM
Last Post: Pir8Radio
Smile please help me remove error for string.strip() jamie_01 3 1,231 Oct-14-2022, 07:48 AM
Last Post: Pedroski55
  strip() pprod 8 3,492 Feb-16-2021, 01:11 PM
Last Post: buran
  Remove escape characters / Unicode characters from string DreamingInsanity 5 13,830 May-15-2020, 01:37 PM
Last Post: snippsat
  Need help with code for my WS2812B (Neopixel) Led Strip Phibbl 1 2,786 Apr-08-2020, 07:18 PM
Last Post: deanhystad
  split strip issues 'NonType' casacafe 8 3,936 Oct-08-2019, 06:29 PM
Last Post: ichabod801
  removing spaces/tabs after used .strip() zarize 0 1,610 Sep-11-2019, 12:46 PM
Last Post: zarize
  strip off just newlines Skaperen 11 5,391 Jun-19-2019, 06:28 PM
Last Post: Skaperen
  strip space from end of a row of text ineuw 4 2,928 Apr-15-2019, 03:14 AM
Last Post: ineuw
  How to remove whitespace from a string when .replace and .strip do not work winnetrie 7 4,497 Jan-05-2019, 08:44 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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