title: "Response_status": "Invalid data provided", "Error": null}
body: <p>I am in a project of migrating an old project which is in python 2.6 to the newest current version.</p>
  <p><strong>python 2</strong></p>
  <pre><code>except Exception,e:
                      
                      return HttpResponse(status=500,content_type=&quot;application/json&quot;,content=json.dumps({'Response':'Failure','Response_status':'Invalid data provided','Error':e.message}))
  </code></pre>
  <p>I have changed to this</p>
  <p><strong>python 3</strong></p>
  <pre><code>except Exception as e:
                      
                      return HttpResponse(status=500,content_type=&quot;application/json&quot;,content=json.dumps({'Response':'Failure','Response_status':'Invalid data provided','Error':print(e)}))
  
  </code></pre>
  <p>*Note: Tried 'Error':e, 'Error':str(e) and 'Error':e.<strong>str</strong>()</p>
  <p>But got a 500 response error like this</p>
  <p><em>{&quot;Response&quot;: &quot;Failure&quot;, &quot;Response_status&quot;: &quot;Invalid data provided&quot;, &quot;Error&quot;: null}</em></p>
  <p>Need help to solve this issue guys!</p>
  <p>Update...This is my views.py</p>
  <pre><code>def registerUser(request):
      # permission_classes = (permissions.IsAuthenticated,)
      if request.method == 'POST':
          try:
              received_json_data=json.loads(request.body)
              referralid=received_json_data.get('referralid')
              received_json_data[&quot;name&quot;]=str(received_json_data.get(&quot;firstname&quot;))+' '+str(received_json_data.get(&quot;lastname&quot;))
              latestid=1
              if tbl_user_profile.objects.all().count()&gt;0:
                  latestid=tbl_user_profile.objects.latest('userid').userid + 1
  
              serializer = tbl_user_profileSerializer(data=received_json_data)
              if serializer.is_valid(): 
                  try: 
                      if str(received_json_data.get('role')) == '3':
                          yearsago = datetime.now() - relativedelta(years=25)
                          serializer.save(dob=yearsago.date(),gender=1,userid=latestid)
                          emailid = serializer.data.get('emailid')
                          username = serializer.data.get('name')
                          password = received_json_data.get('password')
                          userid=serializer.data.get('userid')
  
                          role=tbl_role.objects.get(roleid=received_json_data.get('role'))
  
                          user=tbl_user_profile.objects.get(userid=userid)
                          myuservalues=MyUsers.objects.create_user(username,emailid,password)
                          myuservalues.userid=user
                          myuservalues.roleid=role
                          myuservalues.userPassword=password
                          myuservalues.save()
  
                          usersettings=tbl_user_settings.objects.create(user_id_id=user.userid,isprivacy=1)
                          usersettings.save()
  
  
  
                          if referralid is not None and len(str(referralid))&gt;0:
                              relation=tbl_coach_user_mapping.objects.create(coachid_id=referralid,userid_id=userid,status=2)
    
  
                          response=sendMail(str(emailid), str(password), '/templates/CyberHealth/registrationTemplate.html', 'CyberHealths Registration',None)
                          verifyMyEmail(userid)
                          user={'Response':'Success','Response_status':'', 'User_Profile':serializer.data}
                          if response=='Success':
                              return JsonResponse(user)
                          else:
                              #Error occured while email send
                              return HttpResponse(status=500,content_type=&quot;application/json&quot;,content=json.dumps({'Response':'Failure','Response_status':'Invalid data provided','Error':response}))
                      else:
                          return HttpResponse(status=403,content_type=&quot;application/json&quot;,content=json.dumps({'Response':'Failure','Response_status':'User not allowed'}))
                  except Exception as e:
                      return HttpResponse(status=500,content_type=&quot;application/json&quot;,content=json.dumps({'Response':'Failure','Response_status':'Invalid data provided','Error':print(e)}))
              else:
                  return HttpResponse(status=500,content_type=&quot;application/json&quot;,content=json.dumps({'Response':'Failure','Response_status':'Invalid data provided','Error':serializer.errors}))
          except Exception as e:
              return HttpResponse(status=500,content_type=&quot;application/json&quot;,content=json.dumps({'Response':'Failure','Response_status':'Invalid data provided','Error':print(e)}))
      else:
          return HttpResponse(status=405,content_type=&quot;application/json&quot;,content=json.dumps({'Response':'Failure','Response_status':'Method not allowed'}))
  
  
  </code></pre>