Django:必须指定十六进制,字节,bytes_le,字段或int参数之一

时间:2019-01-07 20:36:47

标签: python django

我正在尝试使用Django在API中基于UUIDAutoField过滤数据。我正在使用PostgreSQL,但是在从移动应用发送数据时,我有一个字符串,并且该字符串UUID在API级别上与同一UUID不匹配,这给了我这个错误:

  / api / updatestate /中的

TypeError   必须给出十六进制,字节,bytes_le,字段或int参数之一

当我从API请求中获取uuid时,我正在执行此操作以字符串化uuid

  

empId = uuid.UUID(request.POST.get('employee_id'))

Traceback:

File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = self.process_exception_by_middleware(e, request)

File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  124.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/app/.heroku/python/lib/python3.6/site-packages/django/views/decorators/csrf.py" in wrapped_view
  54.         return view_func(*args, **kwargs)

File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/views.py" in dispatch
  483.             response = self.handle_exception(exc)

File "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/views.py" in handle_exception
  443.             self.raise_uncaught_exception(exc)

File "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/views.py" in dispatch
  480.             response = handler(request, *args, **kwargs)

File "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/decorators.py" in handler
  53.             return func(*args, **kwargs)

File "/app/cfkcapi/views.py" in checkstate
  78.         empId = uuid.UUID(request.POST.get('employee_id'))

File "/app/.heroku/python/lib/python3.6/uuid.py" in __init__
  134.             raise TypeError('one of the hex, bytes, bytes_le, fields, '

Exception Type: TypeError at /api/updatestate/
Exception Value: one of the hex, bytes, bytes_le, fields, or int arguments must be given

1 个答案:

答案 0 :(得分:1)

错误消息告诉您问题的确切原因:您需要在对uuid.UUID的调用中指定这些参数之一(在views.py的第78行)。 The doc很清楚:

  

必须给出十六进制,字节,bytes_le,字段或整数之一。