'Django: one of the hex, bytes, bytes_le, fields, or int arguments must be given

I am trying to filter data on based of UUIDAutoField in an API using Django. I am using PostgreSQL but while sending data from mobile app I have a string and that string UUID is on API level is not matching up with the same UUID it is giving me this error:

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

and I am doing this to string type uuid when I get it from API request

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


Solution 1:[1]

The error message tells you exactly what the problem is: you need to specify one of those arguments in your call to uuid.UUID (on line 78 of views.py). The doc is pretty clear:

Exactly one of hex, bytes, bytes_le, fields, or int must be given.

Solution 2:[2]

firstly you need to paas argument in uuid.UUID() function. it may be possible that employee id is not coming in your request. so it will pass null. so first make sure that employee_id is not null

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RishiG
Solution 2 Pratz