Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError
#1
Hi

Please could someone help with the error I am getting with my code

Error:
Connected by ('127.0.0.1', 51995) b'PON' Command Screen On Received Traceback (most recent call last): File "c:/Python Code/new test.py", line 55, in <module> server() File "c:/Python Code/new test.py", line 43, in server udp.sendto(packet_to_sned, (Screen_ip_address, UDP_PORT)) TypeError: a bytes-like object is required, not 'str'
s.listen(1)

filepath = 'config.cfg'
with open(filepath) as fp:
   line = fp.readline()
   cnt = 1
   while line:
       if cnt == 1:
           Screen_mac_address = int(line,16)
           print(hex(Screen_mac_address))
       if cnt == 2:
           ip_address = line 
           print(ip_address)
       if cnt == 3:
           Device_2_ip_address = line
           print(Device_2_ip_address)
       line = fp.readline() 
       cnt += 1
   packet_to_sned = (hex(magic_packet_1) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address))
   print(packet_to_sned) 

def server():
    conn, addr = s.accept()
    print ('Connected by', addr)
    while 1:
        data = str(conn.recv(1024))
        print(data)
        if data == "b'PON'":
            print('Command Screen On Received')
            udp.sendto((hex(magic_packet_1) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address) + hex(Screen_mac_address)), (Screen_ip_address, UDP_PORT))
            
        if data == "b'POFF'":
            print('Command Screen Off Received')     
        if not data: break
    conn.close()
    print('Disconnected', addr)
    



while True:
    server()
Reply


Messages In This Thread
TypeError - by omega_elite - Jun-17-2020, 11:05 PM
RE: TypeError - by bowlofred - Jun-17-2020, 11:26 PM
RE: TypeError - by omega_elite - Jun-17-2020, 11:49 PM
RE: TypeError - by bowlofred - Jun-18-2020, 06:53 AM
RE: TypeError - by omega_elite - Jun-18-2020, 09:45 AM
RE: TypeError - by bowlofred - Jun-18-2020, 04:38 PM
RE: TypeError - by omega_elite - Jun-18-2020, 11:08 PM

Forum Jump:

User Panel Messages

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