I'm trying to make sure that when you create an account you create 2 variables that is wallet and bank only that it gives me this specific error:
Ignoring exception in command create:
Traceback (most recent call last):
File "C:\Users\PC GIUSEPPE\PycharmProjects\LMIIBot\venv\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "C:/Users/PC GIUSEPPE/PycharmProjects/LMIIBot/LMII-Bot.py", line 7042, in create
economy_system[id_author]["wallet"] = 100
KeyError: '488826524791734275'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\PC GIUSEPPE\PycharmProjects\LMIIBot\venv\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\PC GIUSEPPE\PycharmProjects\LMIIBot\venv\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\PC GIUSEPPE\PycharmProjects\LMIIBot\venv\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: '488826524791734275'
After many attempts I was unable to solve in any way, how can I solve?
Code:
#client.event
async def on_ready():
global economy_system
try:
with open('economy.json') as f:
economy_system = json.load(f)
except FileNotFoundError:
print("Impossibile caricare amounts.json")
economy_system = {}
#client.command(pass_context=True, aliases=["Create", "CREATE", "register", "Register", "REGISTER", "crea", "Crea", "CREA"])
async def create(ctx):
id_author = str(ctx.author.id)
embed = discord.Embed(
color=0x003399
)
if id_author not in economy_system:
economy_system[id_author]["wallet"] = 100
economy_system[id_author]["bank"] = 0
embed.set_author(
name="Hai creato il tuo account!"
)
await ctx.send(embed=embed, delete_after=10)
_save()
else:
embed.set_author(
name="Hai giĆ registrato un account!"
)
await ctx.send(embed=embed, delete_after=10)
def _save():
with open('economy.json', 'w+') as f:
json.dump(economy_system, f)
economy_system[id_author]["wallet"] = 100
tries to access a dict that does not exist yet.
If you put economy_system[id_author] = {} one line above, the problem should be solved.
"KeyError: '488826524791734275'" means that the author can't be found in economy_system
Related
I am writing a python script that uses signal_handler to capture SIGINT, SIGTSTP signals. The signal handler closes the event loop, which raises a RuntimeError. I'm trying to catch this error and display something else instead. My code is as follows:
async def signal_handler(self):
try :
#perform some cleanup by executing some coroutines
self.loop.stop()
except RuntimeError as err:
print('SIGINT or SIGTSTP raised')
print("cleaning and exiting")
sys.exit(0)
The output is as follows:
^CTraceback (most recent call last):
File "pipeline.py", line 69, in <module>
pipeline(sys.argv[1], (lambda : sys.argv[2] if len(sys.argv)==3 else os.getcwd())())
File "pipeline.py", line 9, in __init__
self.main(link)
File "pipeline.py", line 52, in main
asyncio.run(video.get_file(obj.metadata['name']+"_v."+obj.default_video_stream[1], obj.default_video_stream[0]))
File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.8/asyncio/base_events.py", line 614, in run_until_complete
raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
From the output I can infer that
self.loop.stop()
raised the RuntimeError.
How can I solve this issue?
MRE
Let's start with a Minimal Reproducible Example so that we know we are on the same page:
import asyncio
import signal
import sys
loop = asyncio.new_event_loop()
async def main():
while True:
print('Hey')
await asyncio.sleep(0.5)
async def _signal_handler():
try:
loop.stop()
except RuntimeError as err:
print('SIGINT or SIGTSTP raised')
print("cleaning and exiting")
sys.exit(1)
def signal_handler(*args):
loop.create_task(_signal_handler())
signal.signal(signal.SIGINT, signal_handler)
loop.run_until_complete(main())
This will print the following when SIGINT is received:
Hey
Hey
Hey
^CTraceback (most recent call last):
File "73094030.py", line 26, in <module>
loop.run_until_complete(main())
File "/usr/lib/python3.8/asyncio/base_events.py", line 614, in run_until_complete
raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
Problem
The error will be raised in main(). It happens because the loop is forced to exit before asyncio.sleep() task is finished.
Solution
To solve this, we should cancel the task before exiting. Let's replace
loop.stop()
with
tasks = asyncio.all_tasks(loop)
for task in tasks:
task.cancel()
This still raises an exception:
Hey
Hey
Hey
^CTraceback (most recent call last):
File "73094030.py", line 28, in <module>
loop.run_until_complete(main())
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
asyncio.exceptions.CancelledError
But we have proceeded to change RuntimeError to CancelledError which is more descriptive. It also allows the running functions to run their finally blocks, freeing resources. The event loop will stop automatically after all the tasks finish.
Of course we now except to get a CancelledException. So let's add a try/except block to main():
async def main():
try:
while True:
print('Hey')
await asyncio.sleep(0.5)
except asyncio.CancelledError:
print('\nFunction stopped manually.')
Now we get no clutter:
Hey
Hey
Hey
^C
Function stopped manually.
The final code looks like this:
import asyncio
import signal
import sys
loop = asyncio.new_event_loop()
async def main():
try:
while True:
print('Hey')
await asyncio.sleep(0.5)
except asyncio.CancelledError:
print('\nFunction stopped manually.')
async def _signal_handler():
try:
tasks = asyncio.all_tasks(loop)
for task in tasks:
task.cancel()
except RuntimeError as err:
print('SIGINT or SIGTSTP raised')
print("cleaning and exiting")
sys.exit(1)
def signal_handler(*args):
loop.create_task(_signal_handler())
signal.signal(signal.SIGINT, signal_handler)
loop.run_until_complete(main())
I'm currently making a discord bot in Python. I want to make a command where you have two options for an argument:
An integer to delete a certain amount of messages
And the word 'all' (a string) to delete all the messages in the channel.
I've tried functions like this to determine if it is a string or not...
def isint(s):
try:
int(s)
isint = True
except ValueError:
isint = False
return isint
... but it returns this error:
TypeError: '<=' not supported between instances of 'str' and 'int'
This is the current, most recent code for the command that I have tried:
#commands.command()
#commands.has_role("Clear Chat Key")
async def clear(self, ctx, amount: typing.Union[str, int] = 10):
number = isint(amount)
if number == False:
if amount == 'all':
await ctx.channel.purge(limit = inf)
else:
await ctx.send('Invalid amount.')
if number == True:
await ctx.channel.purge(limit = amount)
else:
await ctx.send('Invalid amount.')
The full traceback for the error, in case it is relevant, is the following:
Traceback (most recent call last):
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: '<=' not supported between instances of 'str' and 'int'
Please bear with me here, I am very new to Python.
EDIT:
Thanks for helping me with this! Here is the code I used in case anyone else needs it:
def is_int(x):
if x.isdigit():
return True
return False
#commands.command()
#commands.has_role("Clear Chat Key")
async def clear(self, ctx, amount: typing.Union[str, int] = 10):
number = is_int(amount)
if number == False:
if amount == 'all':
await ctx.channel.purge(limit = inf)
else:
await ctx.send('Invalid amount.')
if number == True:
amount = int(amount)
await ctx.channel.purge(limit = amount)
else:
await ctx.send('Invalid amount.')
Again, thanks for helping me out!
You're able to use the string's .isdigit() method.
Bear in mind that this will return False for negatives:
>>> my_str = "123"
>>> my_str.isdigit()
True
>>> other_str = "-123"
>>> my_str.isdigit()
False
Working example:
def is_int(some_value):
if some_input.isdigit():
return True
return False
some_input = input("Enter some numbers or words!\n-> ")
print(is_int(some_input))
Reference:
str.isdigit()
Try use this instead of your function isint:
# clear function
number = amount.__class__.__name__ == 'int'
[![Odoo error][1]][1]
I get the below error when i try to reconcile my bank in Odoo 9.
when i click the bank button it does not reconcile
[1]: https://i.stack.imgur.com/PgLmT.png
Gwtting an error when i try to renconsile odoo bank.
Odoo Server Error
Traceback (most recent call last):
File "/odoo/odoo-server/openerp/http.py", line 650, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/odoo/odoo-server/openerp/http.py", line 687, in dispatch
result = self._call_function(**self.params)
File "/odoo/odoo-server/openerp/http.py", line 323, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/odoo/odoo-server/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/odoo/odoo-server/openerp/http.py", line 316, in checked_call
result = self.endpoint(*a, **kw)
File "/odoo/odoo-server/openerp/http.py", line 966, in __call__
return self.method(*args, **kw)
File "/odoo/odoo-server/openerp/http.py", line 516, in response_wrap
response = f(*args, **kw)
File "/odoo/odoo-server/addons/web/controllers/main.py", line 895, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/odoo/odoo-server/addons/web/controllers/main.py", line 887, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/odoo/odoo-server/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/odoo/odoo-server/openerp/addons/base/res/res_currency.py", line 252, in get_format_currencies_js_function
function = "if (arguments[1] === false || arguments[1] === undefined) {" +
company_currency_format + " }" + function
UnboundLocalError: local variable 'company_currency_format' referenced before c
assignment
Oh Dear , saw what the issue was by tailing my sever logs.It turns out i had not assigned an active currency under currency settings.
When I entered the analytic account in Work Center then try to mark the related manufacturing order as done this error occurred
Traceback (most recent call last):
File "/odoo/odoo-server/odoo/http.py", line 638, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/odoo/odoo-server/odoo/http.py", line 675, in dispatch
result = self._call_function(**self.params)
File "/odoo/odoo-server/odoo/http.py", line 331, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/odoo/odoo-server/odoo/service/model.py", line 119, in wrapper
return f(dbname, *args, **kwargs)
File "/odoo/odoo-server/odoo/http.py", line 324, in checked_call
result = self.endpoint(*a, **kw)
File "/odoo/odoo-server/odoo/http.py", line 933, in __call__
return self.method(*args, **kw)
File "/odoo/odoo-server/odoo/http.py", line 504, in response_wrap
response = f(*args, **kw)
File "/odoo/odoo-server/addons/web/controllers/main.py", line 866, in call_button
action = self._call_kw(model, method, args, {})
File "/odoo/odoo-server/addons/web/controllers/main.py", line 854, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/odoo/odoo-server/odoo/api.py", line 681, in call_kw
return call_kw_multi(method, model, args, kwargs)
File "/odoo/odoo-server/odoo/api.py", line 672, in call_kw_multi
result = method(recs, *args, **kwargs)
File "/odoo/enterprise/addons/mrp_account/models/mrp_production.py", line 63, in button_mark_done
self._costs_generate()
File "/odoo/enterprise/addons/mrp_account/models/mrp_production.py", line 43, in _costs_generate
value = wc_line.hour * wc.costs_hourAttributeError: 'mrp.workorder' object has no attribute 'hour'
Can anyone help me how to fix it
Thanks in advance
Hi there when running a mapreduce job (CardDriver example) on my cluster (with CDH 5, hive, hdfs, Yarn, cloudera management services) got an error and here is the trace, Any advice is very much appreciated::
[10/Jul/2014 07:42:00 -0700] base ERROR Internal Server Error: /jobbrowser/jobs/job_1403859859091_0003/tasks/task_1403859859091_0003_r_000006/attempts/attempt_1403859859091_0003_r_000006_0
Traceback (most recent call last):
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/build/env/lib/python2.7/site-packages/Django-1.4.5-py2.7.egg/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/apps/jobbrowser/src/jobbrowser/views.py", line 68, in decorate
return view_func(request, *args, **kwargs)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/apps/jobbrowser/src/jobbrowser/views.py", line 357, in single_task_attempt
"task": task
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/desktop/core/src/desktop/lib/django_util.py", line 222, in render
**kwargs)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/desktop/core/src/desktop/lib/django_util.py", line 144, in _render_to_response
return django_mako.render_to_response(template, *args, **kwargs)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/desktop/core/src/desktop/lib/django_mako.py", line 117, in render_to_response
return HttpResponse(render_to_string(template_name, data_dictionary), **kwargs)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/desktop/core/src/desktop/lib/django_mako.py", line 106, in render_to_string_normal
result = template.render(**data_dict)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/build/env/lib/python2.7/site-packages/Mako-0.8.1-py2.7.egg/mako/template.py", line 443, in render
return runtime._render(self, self.callable_, args, data)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/build/env/lib/python2.7/site-packages/Mako-0.8.1-py2.7.egg/mako/runtime.py", line 786, in _render
**_kwargs_for_callable(callable_, data))
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/build/env/lib/python2.7/site-packages/Mako-0.8.1-py2.7.egg/mako/runtime.py", line 818, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/build/env/lib/python2.7/site-packages/Mako-0.8.1-py2.7.egg/mako/runtime.py", line 844, in _exec_template
callable_(context, *args, **kwargs)
File "/tmp/tmplebzDl/jobbrowser/attempt.mako.py", line 198, in render_body
__M_writer(escape(unicode( comps.get_container_link(status, attempt.nodeHttpAddress, attempt.taskTrackerId) )))
AttributeError: Attempt instance has no attribute 'nodeHttpAddress'
[10/Jul/2014 07:42:00 -0700] middleware INFO Processing exception: Attempt instance has no attribute 'nodeHttpAddress': Traceback (most recent call last):
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/build/env/lib/python2.7/site-packages/Django-1.4.5-py2.7.egg/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/apps/jobbrowser/src/jobbrowser/views.py", line 68, in decorate
return view_func(request, *args, **kwargs)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/apps/jobbrowser/src/jobbrowser/views.py", line 357, in single_task_attempt
"task": task
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/desktop/core/src/desktop/lib/django_util.py", line 222, in render
**kwargs)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/desktop/core/src/desktop/lib/django_util.py", line 144, in _render_to_response
return django_mako.render_to_response(template, *args, **kwargs)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/desktop/core/src/desktop/lib/django_mako.py", line 117, in render_to_response
return HttpResponse(render_to_string(template_name, data_dictionary), **kwargs)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/desktop/core/src/desktop/lib/django_mako.py", line 106, in render_to_string_normal
result = template.render(**data_dict)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/build/env/lib/python2.7/site-packages/Mako-0.8.1-py2.7.egg/mako/template.py", line 443, in render
return runtime._render(self, self.callable_, args, data)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/build/env/lib/python2.7/site-packages/Mako-0.8.1-py2.7.egg/mako/runtime.py", line 786, in _render
**_kwargs_for_callable(callable_, data))
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/build/env/lib/python2.7/site-packages/Mako-0.8.1-py2.7.egg/mako/runtime.py", line 818, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/opt/cloudera/parcels/CDH-5.0.2-1.cdh5.0.2.p0.13/lib/hue/build/env/lib/python2.7/site-packages/Mako-0.8.1-py2.7.egg/mako/runtime.py", line 844, in _exec_template
callable_(context, *args, **kwargs)
File "/tmp/tmplebzDl/jobbrowser/attempt.mako.py", line 198, in render_body
__M_writer(escape(unicode( comps.get_container_link(status, attempt.nodeHttpAddress, attempt.taskTrackerId) )))
AttributeError: Attempt instance has no attribute 'nodeHttpAddress'
It seems like the task is no running yet?
Similar to https://review.cloudera.org//r/4304/