From 179bb51ca7eb13b23a0692f638c92ea8a058f965 Mon Sep 17 00:00:00 2001 From: PengfeiLi0218 Date: Tue, 29 Jan 2019 20:45:24 +0800 Subject: [PATCH] https://github.com/OpenBankProject/API-Manager/pull/67 user None exception in users\views --- apimanager/obp/api.py | 4 ++-- apimanager/obp/oauth.py | 2 +- apimanager/users/views.py | 31 +++++++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/apimanager/obp/api.py b/apimanager/obp/api.py index ddc98ef6..49a9dcdd 100644 --- a/apimanager/obp/api.py +++ b/apimanager/obp/api.py @@ -53,9 +53,9 @@ def call(self, method='GET', url='', payload=None): time_start = time.time() try: if payload: - response = session.request(method, url, json=payload) + response = session.request(method, url, json=payload, verify=False) else: - response = session.request(method, url) + response = session.request(method, url, verify=False) except ConnectionError as err: raise APIError(err) time_end = time.time() diff --git a/apimanager/obp/oauth.py b/apimanager/obp/oauth.py index e0316428..04463648 100644 --- a/apimanager/obp/oauth.py +++ b/apimanager/obp/oauth.py @@ -35,7 +35,7 @@ def get_authorization_url(self, callback_uri): ) try: url = settings.API_HOST + settings.OAUTH_TOKEN_PATH - response = session.fetch_request_token(url) + response = session.fetch_request_token(url, verify=False) except (ValueError, TokenRequestDenied, ConnectionError) as err: raise AuthenticatorError(err) else: diff --git a/apimanager/users/views.py b/apimanager/users/views.py index 56a9e39b..d80e6ba1 100644 --- a/apimanager/users/views.py +++ b/apimanager/users/views.py @@ -57,6 +57,9 @@ def get_users_rolenames(self, context): except APIError as err: messages.error(self.request, err) return [], [] + except: + messages.error(self.request, "Unknown Error") + return [], [] role_names = [] try: @@ -66,6 +69,9 @@ def get_users_rolenames(self, context): except KeyError as err: messages.error(self.request, 'KeyError: {}'.format(err)) return [], [] + except: + messages.error(self.request, "Unknown Error") + return [], [] role_names = list(set(role_names)) role_names.sort() @@ -93,10 +99,15 @@ def get_context_data(self, **kwargs): users = api.get(urlpath) except APIError as err: messages.error(self.request, err) + except: + messages.error(self.request, 'Unknown Error') role_names = self.get_users_rolenames(context) - users = FilterRoleName(context, self.request.GET) \ - .apply([users] if username else users['users']) + try: + users = FilterRoleName(context, self.request.GET) \ + .apply([users] if username else users['users']) + except: + users = [] context.update({ 'role_names': role_names, 'statistics': { @@ -124,6 +135,8 @@ def get_form(self, *args, **kwargs): form.fields['bank_id'].choices = self.api.get_bank_id_choices() except APIError as err: messages.error(self.request, err) + except: + messages.error(self.request, 'Unknown Error') return form def form_valid(self, form): @@ -139,6 +152,9 @@ def form_valid(self, form): except APIError as err: messages.error(self.request, err) return super(DetailView, self).form_invalid(form) + except: + messages.error(self.request, 'Unknown Error') + return super(DetailView, self).form_invalid(form) msg = 'Entitlement with role {} has been added.'.format( entitlement['role_name']) @@ -157,6 +173,8 @@ def get_context_data(self, **kwargs): context['form'].fields['user_id'].initial = user['user_id'] except APIError as err: messages.error(self.request, err) + except: + messages.error(self.request, 'Unknown Error') context.update({ 'apiuser': user, # 'user' is logged-in user in template context @@ -179,6 +197,8 @@ def get_form(self, *args, **kwargs): form.fields['bank_id'].choices = self.api.get_bank_id_choices() except APIError as err: messages.error(self.request, err) + except: + messages.error(self.request, 'Unknown Error') return form def form_valid(self, form): @@ -194,6 +214,9 @@ def form_valid(self, form): except APIError as err: messages.error(self.request, err) return super(MyDetailView, self).form_invalid(form) + except: + messages.error(self.request, 'Unknown Error') + return super(MyDetailView, self).form_invalid(form) msg = 'Entitlement with role {} has been added.'.format( entitlement['role_name']) @@ -212,6 +235,8 @@ def get_context_data(self, **kwargs): context['form'].fields['user_id'].initial = user['user_id'] except APIError as err: messages.error(self.request, err) + except: + messages.error(self.request, 'Unknown Error') context.update({ 'apiuser': user, # 'user' is logged-in user in template context @@ -234,6 +259,8 @@ def post(self, request, *args, **kwargs): messages.success(request, msg) except APIError as err: messages.error(request, err) + except: + messages.error(self.request, 'Unknown Error') redirect_url = request.POST.get('next', reverse('users-index')) return HttpResponseRedirect(redirect_url)