Im trying to receive data in json format in django restframework and utilize the data immediately but i realize i get error that 'NoneType' object is not subscriptable' and i feel that i need to use cleaned_data but i dont know how to use cleaned_data in rest framework...here is my code:
@api_view(['GET', "POST"])
def home(request):
if request.method == 'POST':
name = request.data.get('name')
email = request.data.get("email")
amount = request.data.get("amount")
phone = request.data.get("phone")
return redirect(str(process_payment(name, email, amount, phone)))
else:
responseData = {
"Homepage": "Payment"
}
return Response(responseData)
Here is my traceback error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/views/generic/base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/rest_framework/decorators.py", line 50, in handler
return func(*args, **kwargs)
File "/Users/williamdapper/Desktop/payment/electronics/views.py", line 21, in home
return redirect(process_payment(name, email, amount, phone))
File "/Users/williamdapper/Desktop/payment/electronics/views.py", line 55, in process_payment
link=response['data']['link']
TypeError: 'NoneType' object is not subscriptable
[11/Oct/2021 15:19:25] "POST / HTTP/1.1" 500 95799
[That is the image of the error im getting below][1] [1]: https://i.stack.imgur.com/wkOwa.png
CodePudding user response:
I have fixed it. I printed the response at the process payment to see the error message, so I got:
{'status': 'error', 'message': 'Invalid authorization key', 'data': None}
I now remember that I altered my secret key in the morning, so I got it from my dashboard and made the necessary corrections and everything started working. Thank y'all