This is my first post. I am getting the error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "intruder.py", line 47, in <module>
main()
File "intruder.py", line 16, in main
readfile()
File "intruder.py", line 34, in readfile
pickle.load(f)
File "/usr/lib/python2.7/pickle.py", line 1378, in load
return Unpickler(file).load()
File "/usr/lib/python2.7/pickle.py", line 858, in load
dispatch[key](self)
File "/usr/lib/python2.7/pickle.py", line 880, in load_eof
raise EOFError
EOFError
For code:
#!/usr/bin/python
import getpass
import bz2
import pickle
import marshal
import os, sys
global data
global firsttime
global password
global user
fp = open("firsttime.txt", "r")
data = fp.read();
firsttime = data
def main():
readfile()
name = raw_input('What is your name? ')
if name == user:
user_input = getpass.getpass('Enter Password: ')
if user_input != password:
print "Intruder alert!"
main()
if name != user:
print "Intruder alert!"
main()
print "Login Successful! "
def savefile():
n = open("settings.pkl", 'wb')
pickle.dump(user, n, 2)
pickle.dump(password, n, 2)
n.close()
def readfile():
f = open("settings.pkl", "rb")
pickle.load(f)
f.close()
if data < 1:
user = raw_input ("Enter desired username: ")
password = getpass.getpass('Enter desired password: ')
# encrypted_password = bz2.compress(password)
# bz2.decompress(encrypted_password)
data = 2
g = open("firsttime.txt", "rb")
outf.write(g(data))
g.close()
savefile()
if data > 1:
main()
EDIT: I fixed the above problem. I changed:
fp = open("firsttime.txt", "r")
to:
fp = file("firsttime.txt", "r")
And now it shows the error:
Traceback (most recent call last):
File "intruder.py", line 47, in <module>
main()
File "intruder.py", line 17, in main
if name == user:
NameError: global name 'user' is not defined
This is strange, because user is defined as the user's raw_input, and it askes me for it right before this error appears.
The global keyword tells Python that you're refering to a global variable.
It doesn't create the variable.
You need to change to the following.
Global defs, remove the global data definitions you have and replace with this:
data = None
firsttime = None
password = None
user = None
Then in your functions you tell Python that you're refering to the global, not a local variable. This is only required to write to the variable, not read from it.
def main():
global user, firsttime, password, user
<snip>
def savefile():
global user, firsttime, password, user
<snip>
def readfile():
global user, firsttime, password, user
<snip>
Apart from that, the code has other issues (fp is never closed, etc), but I won't critique other issues.
Related
I have a basic application. I have no experience working with streamlit. When I try
streamlit run app.py
I get the following error.
Traceback (most recent call last):
File "C:\Users\joelm\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\joelm\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\joelm\AppData\Local\Programs\Python\Python310\Scripts\streamlit.exe\__main__.py", line 4, in <module>
File "C:\Users\joelm\AppData\Local\Programs\Python\Python310\lib\site-packages\streamlit\__init__.py", line 55, in <module>
from streamlit.delta_generator import DeltaGenerator as _DeltaGenerator
File "C:\Users\joelm\AppData\Local\Programs\Python\Python310\lib\site-packages\streamlit\delta_generator.py", line 45, in <module>
from streamlit.elements.arrow_altair import ArrowAltairMixin
File "C:\Users\joelm\AppData\Local\Programs\Python\Python310\lib\site-packages\streamlit\elements\arrow_altair.py", line 42, in <module>
from streamlit.elements.utils import last_index_for_melted_dataframes
File "C:\Users\joelm\AppData\Local\Programs\Python\Python310\lib\site-packages\streamlit\elements\utils.py", line 82, in <module>
) -> LabelVisibilityMessage.LabelVisibilityOptions.ValueType:
File "C:\Users\joelm\AppData\Local\Programs\Python\Python310\lib\site-packages\google\protobuf\internal\enum_type_wrapper.py", line 114, in __getattr__
raise AttributeError('Enum {} has no value defined for name {!r}'.format(
AttributeError: Enum LabelVisibilityOptions has no value defined for name 'ValueType'
I have installed streamlit, mysql, mysql.connector
app.py
import streamlit as st
from gui.login.login import login_Main
login_Main()
login.py inside gui/login/
import streamlit as st
# from user import login
# Third change in april
#from controller import *
headerSection = st.container()
mainSection = st.container()
loginSection = st.container()
logOutSection = st.container()
def login_Main():
login()
class login():
def show_main_page(self):
with mainSection:
dataFile = st.text_input("Enter your Test file name: ")
Topics = st.text_input("Enter your Model Name: ")
ModelVersion = st.text_input("Enter your Model Version: ")
processingClicked = st.button ("Start Processing", key="processing")
if processingClicked:
st.balloons()
def LoggedOut_Clicked(self):
st.session_state['loggedIn'] = False
def show_logout_page(self):
loginSection.empty();
with logOutSection:
st.button ("Log Out", key="logout", on_click=self.LoggedOut_Clicked)
def LoggedIn_Clicked(self,userName, password):
if (userName - password):
st.session_state['loggedIn'] = True
else:
st.session_state['loggedIn'] = False
st.error("Invalid user name or password")
def show_login_page(self):
with loginSection:
if st.session_state['loggedIn'] == False:
userName = st.text_input (label="", value="", placeholder="Enter your user name")
password = st.text_input (label="", value="",placeholder="Enter password", type="password")
st.button ("Login", on_click=self.LoggedIn_Clicked, args= (userName, password))
def __init__(self):
with headerSection:
st.title("Streamlit Application")
#first run will have nothing in session_state
if 'loggedIn' not in st.session_state:
st.session_state['loggedIn'] = False
self.show_login_page()
else:
if st.session_state['loggedIn']:
self.show_logout_page()
self.show_main_page()
else:
self.show_login_page()
This is just a login window. This works on another pc but not in mine. What could be wrong.
I have
python -V = 3.10.0
I have tried installing python version 3.11.0. regular python code files work just fine.
I think you should revert to streamlit 1.14 for the moment, there is a problem with 1.15.0, some issues are opened : https://github.com/streamlit/streamlit/issues/5742, https://github.com/streamlit/streamlit/issues/5743
Traceback (most recent call last):
File "C:\Users\me\folder\project.py", line 999, in <module>
load_data()
File "C:\Users\me\folder\project.py", line 124, in load_data
globals()[var_name] = pickle.(f)
EOFError: Ran out of input
I get this error when trying to unpickle a file, even though the file is non-empty. I've tried opening the file and printing its value and it is non-empty, but the unpickler returns this result still.
Anyone know why this may be happening?
The code here is as follows:
files_to_load = ['var1','var2',...]
def load_data():
for var_name in files_to_load:
path = '{}.txt'.format(var_name)
if os.path.exists(path):
with open(path, 'rb') as f:
globals()[var_name] = pickle.Unpickler(f).load()
else: globals()[var_name] = {}
Hi I am trying to make a simple login in system and having problems with hashing the password and comparing it with the users input using bcrypt using tkinter in python 3. I think I have encoded/decoded them properly but now i am getting the error message "invalid salt", any suggestions?
error code:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Kev\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:/Users/Kev/IdeaProjects/HelloWorld/Login/login.py", line 296, in <lambda>
command=lambda: [sign_in(), root.withdraw()])
File "C:/Users/Kev/IdeaProjects/HelloWorld/Login/login.py", line 33, in sign_in
if sign_in_verification():
File "C:/Users/Kev/IdeaProjects/HelloWorld/Login/login.py", line 54, in sign_in_verification
if bcrypt.checkpw(pw, pw_to_check):
File "C:\Users\Kev\AppData\Local\Programs\Python\Python38\lib\site-packages\bcrypt\__init__.py", line 107, in checkpw
ret = hashpw(password, hashed_password)
File "C:\Users\Kev\AppData\Local\Programs\Python\Python38\lib\site-packages\bcrypt\__init__.py", line 86, in hashpw
raise ValueError("Invalid salt")
ValueError: Invalid salt
password = tk.StringVar()
raw_password = r"{}".format(password) # convert tkinter string variable to raw string
hashed_password = bcrypt.hashpw(raw_password.encode("utf-8"), bcrypt.gensalt()) # generate hashed pw
def add_account():
new_password_info = hashed_password.decode("utf-8")
new_username_info = username.get()
file = open(file_name, "a")
file.write(new_username_info + "." + new_password_info ")
file.close()
def sign_in_verification():
pw = password.get().encode("utf-8") # encode password
if username.get() == "" or pw == "":
return False
else:
for line in open(file_name, "r").readlines():
login_info = line.strip().split(".")
if username.get() == login_info[0]:
pw_to_check = login_info[1].encode("utf-8") #
# check passwords match
if bcrypt.checkpw(pw, pw_to_check):
return True
can anyone help? I got an error when I was trying to test a simple code with napalm. I used cisco on GNS3. I also added optional arguments (delay_factor), but it got the same error.
from napalm import get_network_driver
driver = get_network_driver("ios")
others = {
"secret" : "cisco",
"dest_file_system" : "nvram:",
'delay_factor': 5
}
device = driver(hostname="192.168.124.148", username="cisco", password="cisco", optional_args=others)
device.open()
device.load_merge_candidate(filename="candidate")
compare = device.compare_config()
print(compare)
device.commit_config()
device.close()
Traceback (most recent call last):
File "c.py", line 16, in <module>
device.commit_config()
File "/Users/zakky.muhammad/Downloads/tmp/Env/lib/python3.8/site-packages/napalm/ios/ios.py", line 555, in commit_config
output += self.device.save_config()
File "/Users/zakky.muhammad/Downloads/tmp/Env/lib/python3.8/site-packages/netmiko/cisco/cisco_ios.py", line 37, in save_config
return super(CiscoIosBase, self).save_config(
File "/Users/zakky.muhammad/Downloads/tmp/Env/lib/python3.8/site-packages/netmiko/cisco_base_connection.py", line 224, in save_config
output = self.send_command(command_string=cmd)
File "/Users/zakky.muhammad/Downloads/tmp/Env/lib/python3.8/site-packages/netmiko/base_connection.py", line 1335, in send_command
raise IOError(
OSError: Search pattern never detected in send_command_expect: R\#
You can use the code that I have shared below.
from napalm import get_network_driver
driver = get_network_driver('eos')
device = driver('ip_address', 'username', 'password')
device.open()
device.load_replace_candidate(filename='device.conf')
print (device.compare_config())
if len(device.compare_config()) > 0:
choice = input("\nWould you like to Replace the Configuration file? [yN]: ")
if choice == 'y':
print('Committing ...')
device.commit_config()
choice = input("\nWould you like to Rollback to previous config? [yN]: ")
if choice == 'y':
print('Rollback config is in progress ...')
device.rollback()
else:
print('Discarding ...')
device.discard_config()
else:
print ('No difference')
device.close()
print('Done.')
I am new to programming and I created a son program that stores your name, than the items in your list.
import json
list_ = []
filename = 'acco.json'
try:
with open(filename) as f_obj:
username = json.load(f_obj)
except FileNotFoundError:
username = input("What is your name? ")
while True:
list_items = input("What is the item you want to add? q to quit")
if list_items == 'q':
break
list_.append(list_items)
with open(filename, 'w') as f_obj:
json.dump(username, f_obj)
print("These is your list of items:")
print(list_)
print("We'll remember you when you come back, " + username + "!")
json.dump(list_items, f_obj)
else:
print("Welcome back, " + username + "!")
print("Here are the items of your list:")
print(_list)
However, an error keeps showing up when I run the program. The error says that there is an error in line 8, the line of code where it says
username = json.load(f_obj)
This is the exact error
Traceback (most recent call last):
File "/Users/dgranulo/Documents/rememberme.py", line 8, in <module>
username = json.load(f_obj)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 296, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 340, in decode
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 8 (char 7)
If anyone can help that would be greatly appreciated,
Thanks,
You're serializing objects one by one. A str and a list. Do it once in a collection like a list or dict.
This one works;
>>> print(json.loads('"a"'))
a
But this one a str and a list is an error;
>>> json.loads('"a"[1]')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.6/json/decoder.py", line 342, in decode
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 4 (char 3)
Write to the file with a dict;
with open(filename, 'w') as f_obj:
# json.dump(username, f_obj)
print("These is your list of items:")
print(list_)
print("We'll remember you when you come back, " + username + "!")
# json.dump(list_items, f_obj)
# dump a dict
json.dump({'username': username, 'items': list_}, f_obj)
Now json.load will return a dict with keys username and items.