0

I tried to some solutions in the other questions but couldn't solve. Here is my code:

#/usr/bin/env python
#-*- coding: UTF-8 -*-
import socket
import sys
ip = "192.168.0.28"
port = 21
data = "hckn"*250
try:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    conn = s.connect((ip,port))
except:
    print("[-] Baglanti basarisiz")
    sys.exit()

s.recv(1024)
s.send("USER anonymous\r\n".encode('utf-8'))
s.recv(1024)
s.send("PASS anonymous\r\n".encode('utf-8'))
print("[+]Gizli baglanti saglandi")


s.recv(1024)

s.send('MKD'+data+'\r\n'.encode('ascii'))
print("Data yollandı")
s.recv(1024)
s.send('QUIT\r\n'.encode('utf-8'))
s.close()

print("[+]Program yakinda hata verecek...")

when i erase the 'encode's and run it Python2, it works fine. But not on Python3, it says

s.send('MKD'+data+'\r\n'.encode('ascii'))

TypeError: can't convert bytes to object 'str' implicity

1
  • the default encoding in Python 3 is unicode, so you dont need to specify coding (the 2nd line) Commented Feb 4, 2017 at 10:35

2 Answers 2

3

This happens because parentheses are missing:

s.send(('MKD'+data+'\r\n').encode('ascii'))
#      ^                 ^

But the typical solution is to just use bytes to begin with:

data = b"hckn"*250
s.send(b'MKD'+data+b'\r\n')
Sign up to request clarification or add additional context in comments.

Comments

0

On that line:

s.send('MKD'+data+'\r\n'.encode('ascii'))

You need to put parantheses around the 'MKD'+data+'\r\n'. Like this:

s.send(('MKD'+data+'\r\n').encode('ascii'))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.