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
#6
I managed to get this far on the code. It now works and strips out the information I want and presents it, but I'm now trying to figure out how to send the information received to another computer. I'm not sure how I'm supposed to send the information. I've tried a few different basic methods and now I'm stuck at this point: I tried creating a secondary socket figuring I had to in order to send the data forward to a different machine, but I've fought with getting different errors.

import socket, sys

host = ''               
port = 65432
socksize = 19

host2 = '192.168.1.228:65431'
socksize = 19

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:
        host2.send(bytes("Hey there!!", "utf-8"))
        #host2.send("data")
        data = data.decode('utf-8')
        print(data)
        print(remove_punc(data))
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  extract only text strip byte array Pir8Radio 7 3,083 Nov-29-2022, 10:24 PM
Last Post: Pir8Radio
Smile please help me remove error for string.strip() jamie_01 3 1,268 Oct-14-2022, 07:48 AM
Last Post: Pedroski55
  strip() pprod 8 3,573 Feb-16-2021, 01:11 PM
Last Post: buran
  Remove escape characters / Unicode characters from string DreamingInsanity 5 14,007 May-15-2020, 01:37 PM
Last Post: snippsat
  Need help with code for my WS2812B (Neopixel) Led Strip Phibbl 1 2,815 Apr-08-2020, 07:18 PM
Last Post: deanhystad
  split strip issues 'NonType' casacafe 8 4,001 Oct-08-2019, 06:29 PM
Last Post: ichabod801
  removing spaces/tabs after used .strip() zarize 0 1,628 Sep-11-2019, 12:46 PM
Last Post: zarize
  strip off just newlines Skaperen 11 5,484 Jun-19-2019, 06:28 PM
Last Post: Skaperen
  strip space from end of a row of text ineuw 4 2,964 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,579 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