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

Question:

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
Asked By: Ahmad Ayyaz

||

Answers:

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.

Answered By: RishiG

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

Answered By: Pratz

I know this is unbelievably stupid, but if you’re here and the original answer didn’t help you – make sure you don’t happen to call uuid.UUID() anywhere in your code.

For me it slipped in accidentally as I moved some code around and it took me a while to figure it out as I wasn’t expecting it

Answered By: jonyB
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.