'Redis TypeError: must be string or buffer, not None
I want to set a django model in my redis data store, and then in another view function, I want to get it and reuse it again; but it turns out to say:
TypeError: must be string or buffer, not None.
This is my code in views.py:
connection = redis.Redis('localhost')
def recharge_account(request):
cur = recharge_form.cleaned_data['currency']
amnt = recharge_form.cleaned_data['amount']
user_profile = models.UserProfile.objects.get(user=models.User.objects.get(id=request.user.id))
user_b_account, created = models.BankAccount.objects.get_or_create(
owner=user_profile,
cur_code=cur,
method=models.BankAccount.DEBIT,
name=request.user.username + '_' + cur + '_InterPay-account',
account_id=make_id()
)
# saving the temporarily deposit in redis
deposit_dict = {"account": user_b_account, "amount": amnt, "banker": user_profile,
"date": user_b_account.when_opened, "cur_code": cur}
pickled_deposit_dict = pickle.dumps(deposit_dict)
cached_deposit_name = str(user_profile.user_id) + "-cachedDeposit"
connection.set(cached_deposit_name, pickled_deposit_dict)
....
def callback_handler(request, amount):
#getting from redis
new_deposit = pickle.loads(
connection.get(str(user_profile.user_id) + "-cachedDeposit"))
deposit = models.Deposit(account=new_deposit['account'], amount=new_deposit['amount'],
banker=new_deposit['banker'],
date=new_deposit['date'], cur_code=new_deposit['cur_code'])
deposit.save()
.....
My question is: is there any problem with my procedure? Is there any problem with saving a django model in redis?
What should I do to get this function to work properly and getting the saved data "not to be None"?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
