以上就是给各位分享is_authenticated,其中也会对引发TypeErrorTypeError:'bool'对象不可调用进行解释,同时本文还将给你拓展Discord.py错误discord.e
以上就是给各位分享is_authenticated,其中也会对引发TypeError TypeError:'bool'对象不可调用进行解释,同时本文还将给你拓展Discord.py错误discord.ext.commands.errors.CommandInvokeError:命令引发了异常:TypeError:'dict'对象不可调用、django:TypeError:“ tuple”对象不可调用、Flask-Login引发TypeError:尝试覆盖is_active属性时无法调用“ bool”对象、model.fit_generator中的“ TypeError:'NoneType'对象不可调用”等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- is_authenticated()引发TypeError TypeError:'bool'对象不可调用(调用ltrptocx异常:typeerror:对象不支持)
- Discord.py错误discord.ext.commands.errors.CommandInvokeError:命令引发了异常:TypeError:'dict'对象不可调用
- django:TypeError:“ tuple”对象不可调用
- Flask-Login引发TypeError:尝试覆盖is_active属性时无法调用“ bool”对象
- model.fit_generator中的“ TypeError:'NoneType'对象不可调用”
is_authenticated()引发TypeError TypeError:'bool'对象不可调用(调用ltrptocx异常:typeerror:对象不支持)
我尝试is_authenticated()
在视图中使用,但收到错误`TypeError:’bool’对象不可调用。为什么会出现此错误,我该如何解决?
@auth.before_app_requestdef before_request(): if current_user.is_authenticated() \ and not current_user.confirmed \ and request.endpoint[:5] != ''auth.'' \ and request.endpoint != ''static'': return redirect(url_for(''auth.unconfirmed''))
答案1
小编典典当您尝试表现对象的方法或功能时,会发生“对象不可调用”错误。
在这种情况下:
current_user.is_authenticated()
您将current_user.is_authenticated表现为一种方法,而不是一种方法。
您必须以这种方式使用它:
current_user.is_authenticated
您在方法或函数(而不是对象)之后使用“()”。
在某些情况下,类可能实现了__call__
也可以调用对象的函数,因此它将是可调用的。
Discord.py错误discord.ext.commands.errors.CommandInvokeError:命令引发了异常:TypeError:'dict'对象不可调用
如何解决Discord.py错误discord.ext.commands.errors.CommandInvokeError:命令引发了异常:TypeError:''dict''对象不可调用?
此代码:
@commands.command(name="currency",aliases=[''ce''])
async def currencyexchange(self,ctx,currency1,currency2,amount:str):
url = "https://www.amdoren.com/api/currency.PHP?api_key=WTkbre7JxKME95tsu62R2bBng42rKE&from=" + currency1 + "&to=" + currency2 + "&amount=" + amount
async with ClientSession() as session:
async with session.get(url) as response:
r = await response.json(content_type=None)
embed = discord.Embed(colour=discord.Colour.purple(),timestamp = ctx.message.created_at,title=f"Currency Rates")
embed.set_footer(text=f"Requested by {ctx.author}")
embed.add_field(name=f"Exchanged",value = f"{r(''amount'')}",inline = False)
await ctx.send(embed=embed)
返回标题显示的错误。不知道我在哪里搞砸了,但是我需要一些帮助。
API返回以下内容:
{
"error" : 0,"error_message" : "-","amount" : 6.31656
}
谢谢
解决方法
在这一行:
embed.add_field(name=f"Exchanged",value = f"{r(''amount'')}",inline = False)
在编写r(''amount'')
时,用括号将r
视为函数。为了从amount
获取r
字段的值,您需要使用方括号。看起来像这样:
embed.add_field(name=f"Exchanged",value = f"{r[''amount'']}",inline = False)
django:TypeError:“ tuple”对象不可调用
收到类型错误,“
tuple”对象不可调用。知道会是什么吗?(不要担心缩进。它会怪异地复制。)我正在尝试基于storeliquor的PackSize创建选择。
Views.py:
def storeliquor(request, store_id, liquor_id): a = StoreLiquor.objects.get(StoreLiquorID=liquor_id)s = Store.objects.get(StoreID=store_id)x = Order.objects.get(storeID=s, Active=True)y = a.OffPremisePricec = a.BottleSizeg = request.POST.get(''OrderAmount'', '''')b = a.PackSizeh = b*2d = b*3e = b*4r = b*5if c == "1750 ML": pack_size = ( (''1'', ''1'') (''3'', ''3'') (b, b) (h, h) (d, d) (e, e) (r, r) )elif c == "1000 ML": pack_size = ( (''1'', ''1'') (''3'', ''3'') (''6'', ''6'') (b, b) (h, h) (d, d) (e, e) (r, r) )elif c == "750 ML": pack_size = ( (''1'', ''1'') (''3'', ''3'') (''6'', ''6'') (b, b) (h, h) (c, d) (e, e) (r, r) ) elif c == "375 ML": pack_size = ( (''3'', ''3'') (''6'', ''6'') (''12'', ''12'') (b, b) (h, h) (d, d) (e, e) (r, r) ) elif c == "200 ML": pack_size = ( (''12'', ''24'') (''24'', ''24'') (b, b) (c, c) (c, d) (e, e) (r, r) ) else: pack_size = ( (b, b) (c, c) (c, d) (e, e) (r, r) )if request.method == "POST": f = AddToOrderForm(request.POST) if f.is_valid(): z = f.save(commit=False) z.TotalPrice = (float(y)) * (float(g)) z.storeliquorID = a z.orderID = x z.save() return HttpResponseRedirect(''/stores/get/%s'' % store_id)else: f = AddToOrderForm() f.fields[''OrderAmount''].choices = pack_size args = {}args[''liquor''] = aargs[''s''] = sargs[''form''] = freturn render(request,''storeliquor.html'', args)
模型文件:
class LiquorOrder(models.Model):LiquorOrderID = models.AutoField(primary_key=True)storeliquorID = models.ForeignKey(StoreLiquor)orderID = models.ForeignKey(Order)OrderAmount = models.CharField(''Order Amount'', max_length=3)TotalPrice = models.DecimalField(''Total Price'', max_digits=5, decimal_places=2)StorePrice = models.DecimalField(''Store Price'', max_digits=5, decimal_places=2)
表格文件:
class AddToOrderForm(forms.ModelForm):class Meta: model = LiquorOrder fields = (''OrderAmount'', ''StorePrice'')
答案1
小编典典您之间缺少逗号(,
):
>>> ((1,2) (2,3))Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: ''tuple'' object is not callable
放入逗号:
>>> ((1,2), (2,3))((1, 2), (2, 3))
Flask-Login引发TypeError:尝试覆盖is_active属性时无法调用“ bool”对象
我想is_active
在Flask-Login中进行修改,以使用户不总是处于活动状态。
默认值始终返回True
,但我将其更改为返回banned
列的值。
根据文档,is_active
应该是一个属性。但是,内部的Flask-Login代码引发了:
TypeError: ''bool'' object is not callable
尝试使用时is_active
。
如何正确使用is_active
来停用某些用户?
class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) banned = db.Column(db.Boolean, default=False) @property def is_active(self): return self.banned
login_user(user, form.remember_me.data)if not force and not user.is_active():TypeError: ''bool'' object is not callable
答案1
小编典典is_active
,is_anonymous
和is_authenticated
均为Flask-Login
0.3的属性。如果要使用它们,请将它们视为属性,不要调用它们。如果要覆盖它们,请记住用修饰它们@property
。
# change fromcurrent_user.is_authenticated()# tocurrent_user.is_authenticated
看来您正在阅读最新版本(0.3)的文档,但使用的是该库的旧版本。版本0.3包含一项重大更改,将这些属性从方法更改为属性。您应该升级到最新版本的Flask-
Login并将其视为属性。
您可以通过使用户的is_active
属性返回来停用用户False
。您返回列值的想法很好。
model.fit_generator中的“ TypeError:'NoneType'对象不可调用”
如何解决model.fit_generator中的“ TypeError:''NoneType''对象不可调用”?
我正在笔记本电脑上协作,训练一个Unet在Camvid数据集上进行图像分割。
https://drive.google.com/file/d/1e7IMp-ho1xkeHgEjoXsd33cpXYRUjGSG/view?usp=sharing
这是错误:
model.fit_generator()出了点问题。谁能看一下collab链接并帮助我修复此错误?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
我们今天的关于is_authenticated和引发TypeError TypeError:'bool'对象不可调用的分享已经告一段落,感谢您的关注,如果您想了解更多关于Discord.py错误discord.ext.commands.errors.CommandInvokeError:命令引发了异常:TypeError:'dict'对象不可调用、django:TypeError:“ tuple”对象不可调用、Flask-Login引发TypeError:尝试覆盖is_active属性时无法调用“ bool”对象、model.fit_generator中的“ TypeError:'NoneType'对象不可调用”的相关信息,请在本站查询。
本文标签: