I'm trying to make it so that when a user enters their name, password, etc, it stores it globally so that the program is able to connect with that name. I've defined the variables at top like this:
global server
server = ""
global nick
nick = ""
global altnick
altnick = ""
global password
password = ""
global channel
channel = ""
Then, when the Tkinter program comes in, the user can use the Entries to enter all the proper values:
networktop = Toplevel(master=root)
networktop.title("Network List")
networktop.geometry("300x220")
Label(networktop, text="Nickname:").pack()
nickbox = Entry(networktop)
nickbox.grid(column="50", row="50")
nickbox.pack()
nick = nickbox.get()
Label(networktop, text="Alternate nick:").pack()
altbox = Entry(networktop)
altbox.grid(column="50", row="50")
altbox.pack()
altnick = altbox.get()
Label(networktop, text="Password:").pack()
pwbox = Entry(networktop, show="*")
pwbox.grid(column="50", row="50")
pwbox.pack()
password = pwbox.get()
Label(networktop, text="Channel to join:").pack()
chanbox = Entry(networktop)
chanbox.grid(column="50", row="50")
chanbox.pack()
channel = chanbox.get()
listvar = StringVar(networktop)
listvar.set("Choose a network...") # default value
listnetwork = OptionMenu(networktop, listvar, "irc.freenode.net")
listnetwork.config(width="50")
listnetwork.grid(column="50", row="50")
listnetwork.pack()
server = listvar.get()
networkconnect = Button(networktop, text="Connect", command=connect)
networkcancel = Button(networktop, text="Cancel", command=networktop.destroy)
networkcancel.pack(side=LEFT)
networkconnect.pack(side=RIGHT)
What I'm trying to achieve here is that when something is entered in (e.g. "NickName") it replaces nick = "" at top with nick = "NickName", so that when "Connect" is pressed it would connect to the server with "NickName". But I get the following error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1470, in __call__
return self.func(*args)
File "C:\Users\dell\Desktop\irchat.py", line 29, in connect
irc.connect((server, 6667))
File "C:\Python27\lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 10049] The requested address is not valid in its context
I feel like I'm being a total noob here and the solution is probably easy as pie. xD
It appears you are getting the value of the entry widget before the user has an opportunity to enter any text. You're creating the widget and then immediately getting the value. Because of this, server is the empty string and thus the socket code is failing.
You don't want to get the value until the user has click the Connect button.
Related
btcli query
Enter wallet name (default): my-wallet-name
Enter hotkey name (default): my-hotkey
Enter uids to query (All): 18
Note that my-wallet-name, my-hotkey where actually correct names. My wallet with one of my hotkeys. And I decided to query the UID 18.
But btcli is returning an error with no specific message
AttributeError: 'Dendrite' object has no attribute 'forward_text'
Exception ignored in: <function Dendrite.__del__ at 0x7f5655e3adc0>
Traceback (most recent call last):
File "/home/eduardo/repos/bittensor/venv/lib/python3.8/site-packages/bittensor/_dendrite/dendrite_impl.py", line 107, in __del__
bittensor.logging.success('Dendrite Deleted', sufix = '')
File "/home/eduardo/repos/bittensor/venv/lib/python3.8/site-packages/bittensor/_logging/__init__.py", line 341, in success
cls()
File "/home/eduardo/repos/bittensor/venv/lib/python3.8/site-packages/bittensor/_logging/__init__.py", line 73, in __new__
config = logging.config()
File "/home/eduardo/repos/bittensor/venv/lib/python3.8/site-packages/bittensor/_logging/__init__.py", line 127, in config
parser = argparse.ArgumentParser()
File "/usr/lib/python3.8/argparse.py", line 1672, in __init__
prog = _os.path.basename(_sys.argv[0])
TypeError: 'NoneType' object is not subscriptable
What does this means?
How can I query an UID correctly?
I have try to look for UIDs to query but the tool does not give me any.
I was expecting a semantic error or a way to look for a UID i can query but not a TypeError.
It appears that command is broken and should be removed.
I opened an issue for you here: https://github.com/opentensor/bittensor/issues/1085
You can use the python API like:
import bittensor
UID: int = 18
subtensor = bittensor.subtensor( network="nakamoto" )
forward_text = "testing out querying the network"
wallet = bittensor.wallet( name = "my-wallet-name", hotkey = "my-hotkey" )
dend = bittensor.dendrite( wallet = wallet )
neuron = subtensor.neuron_for_uid( UID )
endpoint = bittensor.endpoint.from_neuron( neuron )
response_codes, times, query_responses = dend.generate(endpoint, forward_text, num_to_generate=64)
response_code_text = response_codes[0]
query_response = query_responses[0]
I have created a Bank Management System using Tkinter and MySQL in Python.
def deposit_acc_chk():
mycursor.execute("SELECT name FROM bank_master WHERE acno = '"+deposit_entry1.get()+"'")
for x in mycursor:
name_chk = ''.join(map(str, x))
deposit_chk_entry.delete(0, "end")
deposit_chk_entry.insert(0, name_chk)
deposit_chk_entry["state"] = "disabled"
This code snippet displays the name of the Account holder depositing the money. It was working fine initially but then it showed an error.
Traceback (most recent call last):
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:\Users\HP\Desktop\BMS - GUI v1.1.2.py", line 196, in deposit_acc_chk
deposit_chk_entry.insert(0, name_chk)
UnboundLocalError: local variable 'name_chk' referenced before assignment
I tried to declare the variable name_chk, explicitly, as global and even tried referring some already answered questions of this type but it was not much helpful.
My error is still not resolved! Please help me.
P.S. - I am new here so please excuse me if I fail to correctly describe my question!
It is because there is no record returned by the SQL statement, so name_chk is not created.
You should check whether there is record returned before updating deposit_chk_entry:
def deposit_acc_chk():
mycursor.execute('SELECT name FROM bank_master WHERE acno = %s', (deposit_entry1.get(),))
rec = mycursor.fetchone()
if rec:
deposit_chk_entry['state'] = 'normal'
deposit_chk_entry.delete(0, 'end')
deposit_chk_entry.insert(0, rec[0])
deposit_chk_entry['state'] = 'disabled'
Or better show something to user if no record found:
def deposit_acc_chk():
mycursor.execute('SELECT name FROM bank_master WHERE acno = %s', (deposit_entry1.get(),))
rec = mycursor.fetchone()
name_chk = rec[0] if rec else '*** No record found ***'
deposit_chk_entry['state'] = 'normal'
deposit_chk_entry.delete(0, 'end')
deposit_chk_entry.insert(0, name_chk)
deposit_chk_entry['state'] = 'disabled'
You should
declare the name_chk variable before the line (this way, initialization occurs too)
deposit_chk_entry.insert(0, name_chk) such as
import tkinter as tk
root = tk.Tk()
name_chk = tk.StringVar()
or
call deposit_acc_chk() function between end of this function and
the line deposit_chk_entry.insert(0, name_chk) in order to incur the definition of the variable
name_chk within that function
I want to synchronize my input in one file with the variables in another file. Where should I put my return statement in the login function in order to import variables to another file and synchronize there?
I have tried to put return username, password inside the login function and import that login function in other file and get the variables
class main:
def __init__(self, master):
# Window
self.master = master
# Some Usefull variables
self.username = StringVar()
self.password = StringVar()
self.n_username = StringVar()
self.n_password = StringVar()
# Create Widgets
self.widgets()
# Login Function
def login(self):
# Establish Connection
with sqlite3.connect('quitq.db') as db:
c = db.cursor()
return self.username, self.password ### this one I added to try to send other file
# Find user If there is any take proper action
find_user = ('SELECT * FROM user WHERE username = ? and password = ?')
c.execute(find_user, [(self.username.get()), (self.password.get())])
result = c.fetchall()
if result:
self.logf.pack_forget()
self.head['text'] = self.username.get() + '\n Loged In'
self.head['pady'] = 150
top1.deiconify()
else:
ms.showerror('Oops!', 'Username Not Found.')
This is the main file where I tried to use return statement in order to use in the following code:
import datetime
import email
import imaplib
import menu
username, password = menu.main.login()
a = username
b = password
EMAIL_ACCOUNT = a
PASSWORD = b
I'm getting this error:
Traceback (most recent call last):
File "C:code/menu.py", line 4, in <module>
import email_client
File "C:\code\email_client.py", line 4, in <module>
import menu
File "C:\code\menu.py", line 285, in <module>
email_from, email_to, local_message_date, subject, body = email_client.get_email()
AttributeError: module 'email_client' has no attribute 'get_email'
I'm trying to get the names of my top 3 artists of last week with pylast (https://github.com/pylast/pylast) but I run into an error or get I get None as a result and I don't see what I'm doing wrong. pylast is a Python interface to Last.fm.
My code:
import pylast
API_KEY = ""
API_SECRET = ""
username = ""
password_hash = pylast.md5("")
network = pylast.LastFMNetwork(api_key=API_KEY, api_secret=API_SECRET, username=username, password_hash=password_hash)
user = network.get_authenticated_user();
weekly_artists = user.get_weekly_artist_charts();
# Keep the first three artists.
del weekly_artists[3:]
# Print the artist name and number of songs(weight).
for weekly_artist in weekly_artists:
artist,weight = weekly_artist
print (artist.get_name())
print (artist.get_correction())
artist.get_name() returns
None
artist.get_correction() returns
Traceback (most recent call last):
File "G:\projects\python\lastfm_weekly\lastfm-weekly.py", line 28, in <module>
print (artist.get_correction())
File "C:\Users\..\Python\Python36-32\lib\site-packages\pylast\__init__.py", line 1585, in get_correction
self._request(self.ws_prefix + ".getCorrection"), "name")
File "C:\Users\..\Python\Python36-32\lib\site-packages\pylast\__init__.py", line 1029, in _request
return _Request(self.network, method_name, params).execute(cacheable)
File "C:\Users\..\Python\Python36-32\lib\site-packages\pylast\__init__.py", line 744, in __init__
network._get_ws_auth()
AttributeError: 'str' object has no attribute '_get_ws_auth'
What am I doing wrong?
Here is a quick and dirty solution, i'm sure someone will provide something better but i just installed the package to test and it works.
network = pylast.LastFMNetwork(api_key=API_KEY, api_secret=API_SECRET)
artists = network.get_top_artists()
del artists[:3]
for i in artists:
artist, weight = i
print('Artist = {}. Weight = {}'.format(artist, weight))
I'm not really familiar with the package, I just installed it to help out with this but I do wonder what "get_name()" and "get_correction()" are as they're not in your provided code.
If they're not functions you created / are defined within your code then I'd look there for the problem.
Also, you're authenticating the user but the documentation explicitly states you don't need to unless you're writing data.
I'm currently trying to use the pjsip api pjsua in python and therefor studying this Hello World example: http://trac.pjsip.org/repos/wiki/Python_SIP/Hello_World
I copied the code over, integrated account configuration according to http://trac.pjsip.org/repos/wiki/Python_SIP/Accounts etc. But when I run the sample, I get the following output:
Traceback (most recent call last):
File "/home/dmeli/workspace/eit.cubiephone.sip_test/eit/cubiephone/sip_test/hello.py", line 48, in <module>
acc = lib.create_account(acc_cfg)
File "/usr/local/lib/python2.7/dist-packages/pjsua.py", line 2300, in create_account
err, acc_id = _pjsua.acc_add(acc_config._cvt_to_pjsua(), set_default)
File "/usr/local/lib/python2.7/dist-packages/pjsua.py", line 900, in _cvt_to_pjsua
cfg.rtp_transport_cfg = self.rtp_transport_cfg._cvt_to_pjsua()
AttributeError: '_pjsua.Transport_Config' object has no attribute '_cvt_to_pjsua'
Because I'm not really a python expert and never worked with PJSIP before, I can't really figure out the error. Too me, it looks like it's actually an error in the pjsip python wrapper. But what do I know?
Code:
lib = pj.Lib()
lib.init(log_cfg = pj.LogConfig(level=3, callback=log_cb))
transport = lib.create_transport(pj.TransportType.UDP)
lib.start()
acc_cfg = pj.AccountConfig("XXXXX", "XXXXXX", "XXXXXX")
acc_cfg.id = "sip:XXXXXXX#XXXXXXXX"
acc_cfg.reg_uri = "sip:XXXXXXXXX"
acc_cfg.proxy = [ "sip:XXXXXXXXX;lr" ]
acc = lib.create_account(acc_cfg)
# Make call
call = acc.make_call("XXXXXXXXXXX", MyCallCallback())
Line where the error happens in pjsua.py:
cfg.rtp_transport_cfg = self.rtp_transport_cfg._cvt_to_pjsua()
(rtp_transport_cfg doesn't seem to have a member _cvt_to_pjsua()??)
For further work correctly, look at the PJSIP api (pjsua.py) that he is waiting for the order and structure!!!
## start lib.
def start(self):
try:
self._start_lib()
self._start_acc()
except pj.Error:
print "Error starting lib."
def _bind(self):
try:
t = pj.TransportConfig()
t.bound_addr = '0.0.0.0'
t.port = 5060
acc_transport = "udp" # depend if you need.
if acc_transport == "tcp":
self.transport = self.lib.create_transport(pj.TransportType.TCP, t)
# or this pj.TransportConfig(0) is creating random port ...
#self.transport = self.lib.create_transport(pj.TransportType.TCP, pj.TransportConfig(0))
else:
self.transport = self.lib.create_transport(pj.TransportType.UDP, t)
#self.transport = self.lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
except pj.Error:
print "Error creating transport."
#you need create callbacks for app, to work incoming calls, check on the server that returns the error code 200, and such a way your program will know that you are logged on correctly
#from callback.acc_cb import acc_cb
#self.acc_t = self.lib.create_account_for_transport(self.transport, cb=acc_cb())
def _start_lib(self):
self.lib.init(log_cfg = pj.LogConfig(level=3, callback=log_cb))
self.lib.start()
self._bind()
#codecs.load_codecs()
def _start_acc(self):
#from callback.acc_cb import acc_cb
try:
proxy = "sip server ip" # or proxy = socket.gethostbyname(unicode("sip.serverdnsname.com")) is needed to import socket
login = "Atrotygma" # real username
password = "Atrotygma_password" # real username
lib.create_account(acc_config=pj.AccountConfig(proxy, login, password))
except Exception, e:
print "Error creating account", e