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

Sorry posted wrong code and error!!!!also just to let you know I am new to coding !!

Error:
Connected by ('127.0.0.1', 52572) 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.encode('utf-8'), (Screen_ip_address, UDP_PORT)) AttributeError: 'int' object has no attribute 'encode
import socket

magic_packet_1 = 0xFFFFFFFFFFFF
packet_to_sned = 0x00
Screen_mac_address = 0x00
Screen_ip_address = ''
Device_2_ip_address = ''
HOST = ''                 # Symbolic name meaning all available interfaces
PORT = 50007
UDP_PORT = 9
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((HOST, PORT))
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 = (magic_packet_1 + 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(packet_to_sned.encode('utf-8'), (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