'tuple' object is not callable for #renderer_classes((JSONRenderer,)) - django

I got
'tuple' object is not callable
error when using #renderer_classes((JSONRenderer,)) decorators for function. Any idea??

Related

How to solve Attribute Error in Ray Framework?

What does this mean? Can this be fix? Thanks.
AttributeError: ‘ray._raylet.ObjectRef’ object has no attribute ‘raw’

exchangelib consistently returns 'QuerySet' object has no attribute 'iterator' when using chunkify

Problem:
When using exchangelib for large amounts of emails(in this case 10K+) the entire set is attempted to be loaded. I have tried to employ chunkify:
from exchangelib import Credentials, Account
for item in account.inbox\
.filter(is_read=False, sender__contains='gmail')\
.only('is_read', 'subject', 'body') \
.order_by('-datetime_received')\
.iterator():
print('Email subject is:', item.subject)
print('Email is from:', item.sender)
Which yields the following log error:
for item in account.inbox.filter(is_read=False, sender__contains='gmail').only('is_read', 'subject', 'body').order_by('-datetime_received').iterator():
AttributeError: 'QuerySet' object has no attribute 'iterator'
The .iterator() method was deprecated in exchangelib v4.0.0 and finally removed in v4.7.0. exchangelib no longer does any internal caching so the method is a no-op.

unhelpful Pyomo error ERROR: Initializer for Set objective_index returned non-iterable object of type SumExpression

Here is the offending code, abstracted from the source to protect your sanity . . .
def objective_rule(model):
return sum(model.ccv[c] * model.SELECT[c] for c in model.c)
nc=40
model.c = Set(initialize=[c for c in range(1, nc+1)], ordered=True)
model.SELECT=Var(model.c, initialize=0, domain=NonNegativeReals)
model.ccv= Param(model.c, initialize=ccd, domain=NonNegativeReals)
ccd is a dictionary with the same integer keys as as model.c.
Here are the error allegations made by pyomo.
ERROR: Initializer for Set objective_index returned non-iterable object of
type SumExpression.
ERROR: Constructing component 'objective_index' from data=None failed:
TypeError: 'SumExpression' object is not iterable
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In [44], line 1
----> 1 model.objective = Objective(objective_rule, sense = minimize)
3 print("Done setting up the problem.")
...
TypeError: 'SumExpression' object is not iterable
You'll notice that I don't use SumExpression in my code, so an error message that SumExpression is not iterable is not actionable.
The objection function follows the form of many, many other pyomo objective functions that do work fine.
The problem I'm working on is easy to solve in cvxpy, but I'm tasked with getting pyomo to be useful. So far, not so good.
Is there a (nonobvious) error here? Do the error messages contain actionable information? Do I have a broken pyomo installation?
The error is in the construction of your Objective().
pyomo is making the (false) assumption that the first parameter in the function call is an iterable. Most pyomo commands like making variables or constraints with a "rule" assume the first thing(s) in the call are the indexing set(s).
You should identify it by a keyword. Or just put the expression in the function. Either of these should work. (Note the use of 'rule' in the first and 'expr' in the second)
model.objective = Objective(rule=objective_rule) #minimize is default and not needed
or you can ditch the function as it is just a simple expression and put:
model.objective = Objective(expr=sum(model.ccv[c] * model.SELECT[c] for c in model.c))

Getting "AttributeError: 'str' object has no attribute 'regex'" in Django urls.reverse

As in the title, I'm getting
AttributeError: 'str' object has no attribute 'regex'
I've seen many valid answers to this, but none of them applied to my code as they identified issues in the urls.py file. My issue is in the views.py file.
I get the exception when using reverse to generate a redirect URL:
HttpResponseRedirect(reverse('changetracker:detail', args))
When I use 'changetracker:detail' in other functions, I don't get the exception.
I'm answering this to share knowledge as I didn't see this particular root cause identified already.
The problem turned out to be that I should be using a keyword argument 'args=args' to pass in URL arguments, not a positional argument:
HttpResponseRedirect(reverse('changetracker:detail', args=args))
Using the positional argument (position 2) caused reverse to use that argument as the URL list and thus raise the AttributeError.

importing a class object from one file in to another file

I am trying to call a function in class A from One.py file in to Two.py file by using
from one import A
in this class A :in init function i am assigning a variable name i.e; self._fname=name.
Now i am trying to call a function funC() from class A which uses the self._fname varible like below in Two.py
now=A()
now.funC()
when call this function i am getting an Attribute Error :Class A has no attribute '_fname'
func():
if self._fname:
print "found"
How can i resolve this problem.Is there any way that i can import Class A object from one.py to Two.py so by using that object i can access the 'fname' variable.
AttributeError are typically raised when you try to access an attribute or member which is not defined in the object being dealt with. In your case,
you are initializing self._fname and are trying to use self.fname, which in my opinion is not defined in your class 'A' (notice the underscore before 'fname') . so basically, if you try to access the correct member (self._fname) in func() ,your Attribute error would go away !