Полный traceback (heroku):
2020-03-24T16:11:47.624938+00:00 app[web.1]: Internal Server Error: /api/register_domain_name
2020-03-24T16:11:47.624949+00:00 app[web.1]: Traceback (most recent call last):
2020-03-24T16:11:47.624950+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
2020-03-24T16:11:47.624951+00:00 app[web.1]: response = get_response(request)
2020-03-24T16:11:47.624952+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 158, in _get_response
2020-03-24T16:11:47.624952+00:00 app[web.1]: response = self.process_exception_by_middleware(e, request)
2020-03-24T16:11:47.624953+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 156, in _get_response
2020-03-24T16:11:47.624953+00:00 app[web.1]: response = response.render()
2020-03-24T16:11:47.624953+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/template/response.py", line 106, in render
2020-03-24T16:11:47.624954+00:00 app[web.1]: self.content = self.rendered_content
2020-03-24T16:11:47.624954+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/response.py", line 72, in rendered_content
2020-03-24T16:11:47.624955+00:00 app[web.1]: ret = renderer.render(self.data, accepted_media_type, context)
2020-03-24T16:11:47.624955+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/renderers.py", line 105, in render
2020-03-24T16:11:47.624956+00:00 app[web.1]: allow_nan=not self.strict, separators=separators
2020-03-24T16:11:47.624956+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/utils/json.py", line 28, in dumps
2020-03-24T16:11:47.624957+00:00 app[web.1]: return json.dumps(*args, **kwargs)
2020-03-24T16:11:47.624957+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/json/__init__.py", line 238, in dumps
2020-03-24T16:11:47.624958+00:00 app[web.1]: **kw).encode(obj)
2020-03-24T16:11:47.624959+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/json/encoder.py", line 199, in encode
2020-03-24T16:11:47.624959+00:00 app[web.1]: chunks = self.iterencode(o, _one_shot=True)
2020-03-24T16:11:47.624960+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/json/encoder.py", line 257, in iterencode
2020-03-24T16:11:47.624961+00:00 app[web.1]: return _iterencode(o, 0)
2020-03-24T16:11:47.624961+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/utils/encoders.py", line 68, in default
2020-03-24T16:11:47.624962+00:00 app[web.1]: return super(JSONEncoder, self).default(obj)
2020-03-24T16:11:47.624962+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/json/encoder.py", line 180, in default
2020-03-24T16:11:47.624963+00:00 app[web.1]: o.__class__.__name__)
2020-03-24T16:11:47.624963+00:00 app[web.1]: TypeError: Object of type 'DoesNotExist' is not JSON serializable
Это происходит, когда я вызываю api fun c:
@api_view(['POST'])
@permission_classes((IsAuthenticated,))
@authentication_classes((TokenAuthentication,))
@ensure_csrf_cookie
@renderer_classes((JSONRenderer,))
def register_domain_name(request):
if request.method == 'POST':
data = request.POST
address = data.get('address', False)
tot_amt = data.get('tot_amt', False)
blocktime = data.get('blocktime', False)
txid = data.get('txid', False)
try:
user = User.objects.get(userprofile__zeal_address=address)
except Exception as e:
return Response({'status': 'failed', 'error': e })
last_dri = DomainRegistrationItem.objects.filter(user=user).order_by('-request_date')[0]
if tot_amt == last_dri.get_total_price:
domain_name = last_domain_reg_item.domain
domain = Domain.objects.create(name=domain_name, created_by=user)
domain_name_order = DomainNameOrder.objects.create(
from_address=address,
price=tot_amt,
blocktime=blocktime,
txid=txid,
domain_registration_item=last_dri,
domain_item=domain,
years=last_dri.years,
)
last_dri.purchased = True
last_dri.save()
return Response({'status': 'success'})
else:
return Response({'status': 'failed'})
Я думал, что это может иметь какое-то отношение ко мне, пытаясь для .get () объекта («DoesNotExist» не сериализуем), но единственный раз, когда это происходит, я использую попытку / исключение. Я искал ошибку в названии и не получил результатов. Кто-нибудь может помочь?
Кто-нибудь может помочь? Заранее спасибо.