0

Please help me in this code. Error is given below.

Error: socket succesfully created 111 connection failed traceback most recent call last file custom-iec.py line 27 in module s.sendstartdt typeerror send argument 1 must be string buffer list

import socket 
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
a = socket.connect_ex(('XXX.XXX.XXX.XXX', 2500))
#s = socket.socket()
port=2500
a=socket.connect_ex(('XXX.XXX.XXX.XXX', port))
print a
Packet = [

    0x68,
    0x04, 
    0x43,
    0x00, 
    0x00, 
    0x00 
    ]
socket.send(Packet)
print s.recv(256)
s.close
Armali
  • 18,255
  • 14
  • 57
  • 171
Defender
  • 1
  • 1

2 Answers2

0

Do not overwrite the library function socket with your own socket variable. You may encounter problems when doing that.

socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
^^ - better is: s = socket...

But i would recomment that you have a look @ this comment:

import socket

clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
clientsocket.connect(('YOURIP', YOURPORT))   
clientsocket.send('hello')

from https://stackoverflow.com/a/18297623/8619512

Marc Ma
  • 318
  • 2
  • 12
  • I'm using python 2.7.X version, And in this version I should use coonect_ex() function. When I used this function connect(), it gave me an error. – Defender Sep 22 '18 at 09:58
  • and you're sending a only string there in function send('hello'). I think, I'm sending a variable which hold some value. – Defender Sep 22 '18 at 09:59
0

typeerror send argument 1 must be string buffer list

The correct wording of the error message is:

TypeError: send() argument 1 must be string or buffer, not list

And this says it - with Packet = [… you defined a list, while send() expects a string or a buffer. You can define your packet as a string with Packet = "\x68\x04\x43\x00\x00\x00".

Armali
  • 18,255
  • 14
  • 57
  • 171