Skip to content

Commit c8da5b2

Browse files
committed
Fix issues when request.META.get('HTTP_USER_AGENT') is None
1 parent 2d46172 commit c8da5b2

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

rest_framework_sso/models.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ def __str__(self):
5656
return six.text_type(self.id)
5757

5858
def update_attributes(self, request):
59-
self.ip_address = request.META.get('HTTP_X_FORWARDED_FOR') \
60-
if request.META.get('HTTP_X_FORWARDED_FOR') \
61-
else request.META.get('REMOTE_ADDR')
62-
self.user_agent = request.META.get('HTTP_USER_AGENT')[:1000]
59+
if request.META.get('HTTP_X_FORWARDED_FOR'):
60+
self.ip_address = request.META.get('HTTP_X_FORWARDED_FOR')
61+
elif request.META.get('REMOTE_ADDR'):
62+
self.ip_address = request.META.get('REMOTE_ADDR')
63+
else:
64+
self.ip_address = None
65+
66+
if request.META.get('HTTP_USER_AGENT'):
67+
self.user_agent = request.META.get('HTTP_USER_AGENT')[:1000]
68+
else:
69+
self.user_agent = ''

0 commit comments

Comments
 (0)