def get_data_from_request(self, request): result = super().get_data_from_request(request) # Override the user ID with the e-mail address if it exists, or append # the host name if it does not exist. (Because we receive reports from # many sites, the primary key of the user isn't very helpful.) try: user_info = result.get('user') if user_info: if user_info.get('email'): # If there's an e-mail address, just use it. user_info['id'] = user_info['email'] else: # Otherwise, append the host name. host = get_host(request) user_info['id'] = "%s@%s" % (user_info['id'], host) except Exception: # Just make best efforts; if it all fell apart, so be it. pass # Include tournament preferences, if there are any try: tournament = getattr(request, 'tournament', None) if tournament is not None: extra_info = result.setdefault('extra', {}) extra_info['tournament_prefs'] = request.tournament.preferences.all() except Exception as e: pass # again, best efforts only return result
def get_data_from_request(self, request): try: from django.contrib.auth.models import AbstractBaseUser as BaseUser except ImportError: from django.contrib.auth.models import User as BaseUser # NOQA except RuntimeError: # If the contenttype / user applications are not installed trying to # import the user models will fail for django >= 1.9. BaseUser = None result = {} if BaseUser and hasattr(request, 'user') and isinstance( request.user, BaseUser): result['user'] = self.get_user_info(request.user) try: uri = request.build_absolute_uri() except SuspiciousOperation: # attempt to build a URL for reporting as Django won't allow us to # use get_host() if request.is_secure(): scheme = 'https' else: scheme = 'http' host = get_host(request) uri = '%s://%s%s' % (scheme, host, request.path) if request.method not in ('GET', 'HEAD'): try: data = request.body except Exception: try: data = request.raw_post_data except Exception: # assume we had a partial read. try: data = request.POST or '<unavailable>' except Exception: data = '<unavailable>' else: data = None environ = request.META result.update({ 'request': { 'method': request.method, 'url': uri, 'query_string': request.META.get('QUERY_STRING'), 'data': data, 'cookies': dict(request.COOKIES), 'headers': dict(get_headers(environ)), 'env': dict(get_environ(environ)), } }) return result
def get_data_from_request(self, request): try: from django.contrib.auth.models import AbstractBaseUser as BaseUser except ImportError: from django.contrib.auth.models import User as BaseUser # NOQA except RuntimeError: # If the contenttype / user applications are not installed trying to # import the user models will fail for django >= 1.9. BaseUser = None result = {} if BaseUser and hasattr(request, 'user') and isinstance(request.user, BaseUser): result['user'] = self.get_user_info(request.user) try: uri = request.build_absolute_uri() except SuspiciousOperation: # attempt to build a URL for reporting as Django won't allow us to # use get_host() if request.is_secure(): scheme = 'https' else: scheme = 'http' host = get_host(request) uri = '%s://%s%s' % (scheme, host, request.path) if request.method not in ('GET', 'HEAD'): try: data = request.body except Exception: try: data = request.raw_post_data except Exception: # assume we had a partial read. try: data = request.POST or '<unavailable>' except Exception: data = '<unavailable>' else: data = None environ = request.META result.update({ 'request': { 'method': request.method, 'url': uri, 'query_string': request.META.get('QUERY_STRING'), 'data': data, 'cookies': dict(request.COOKIES), 'headers': dict(get_headers(environ)), 'env': dict(get_environ(environ)), } }) return result
def get_data_from_request(self, request): result = {} user = getattr(request, 'user', None) if user is not None: user_info = self.get_user_info(user) if user_info: result['user'] = user_info try: uri = request.build_absolute_uri() except SuspiciousOperation: # attempt to build a URL for reporting as Django won't allow us to # use get_host() if request.is_secure(): scheme = 'https' else: scheme = 'http' host = get_host(request) uri = '%s://%s%s' % (scheme, host, request.path) if request.method not in ('GET', 'HEAD'): try: data = request.body except Exception: try: data = request.raw_post_data except Exception: # assume we had a partial read. try: data = request.POST or '<unavailable>' except Exception: data = '<unavailable>' else: if isinstance(data, MultiValueDict): data = dict( (k, v[0] if len(v) == 1 else v) for k, v in iterlists(data)) else: data = None environ = request.META result.update({ 'request': { 'method': request.method, 'url': uri, 'query_string': request.META.get('QUERY_STRING'), 'data': data, 'cookies': dict(request.COOKIES), 'headers': dict(get_headers(environ)), 'env': dict(get_environ(environ)), } }) return result
def get_data_from_request(self, request): try: from django.contrib.auth.models import AbstractBaseUser as BaseUser except ImportError: from django.contrib.auth.models import User as BaseUser # NOQA result = {} if hasattr(request, "user") and isinstance(request.user, BaseUser): result["user"] = self.get_user_info(request.user) try: uri = request.build_absolute_uri() except SuspiciousOperation: # attempt to build a URL for reporting as Django won't allow us to # use get_host() if request.is_secure(): scheme = "https" else: scheme = "http" host = get_host(request) uri = "%s://%s%s" % (scheme, host, request.path) if request.method != "GET": try: data = request.body except Exception: try: data = request.raw_post_data except Exception: # assume we had a partial read. try: data = request.POST or "<unavailable>" except Exception: data = "<unavailable>" else: data = None environ = request.META result.update( { "request": { "method": request.method, "url": uri, "query_string": request.META.get("QUERY_STRING"), "data": data, "cookies": dict(request.COOKIES), "headers": dict(get_headers(environ)), "env": dict(get_environ(environ)), } } ) return result
def get_data_from_request(self, request): try: from django.contrib.auth.models import AbstractBaseUser as BaseUser except ImportError: from django.contrib.auth.models import User as BaseUser # NOQA result = {} if hasattr(request, 'user') and isinstance(request.user, BaseUser): result['sentry.interfaces.User'] = self.get_user_info(request.user) try: uri = request.build_absolute_uri() except SuspiciousOperation: # attempt to build a URL for reporting as Django won't allow us to # use get_host() if request.is_secure(): scheme = 'https' else: scheme = 'http' host = get_host(request) uri = '%s://%s%s' % (scheme, host, request.path) if request.method != 'GET': try: data = request.body except: try: data = request.raw_post_data and request.raw_post_data or request.POST except Exception: # assume we had a partial read: data = '<unavailable>' else: data = None environ = request.META result.update({ 'sentry.interfaces.Http': { 'method': request.method, 'url': uri, 'query_string': request.META.get('QUERY_STRING'), 'data': data, 'cookies': dict(request.COOKIES), 'headers': dict(get_headers(environ)), 'env': dict(get_environ(environ)), } }) return result
def request2crashreporting(request): """ Transform django/wsgi request object to a dict the crash reporting can understand. """ data = {} # Pieces grabbed from raven.contrib.django.client try: uri = request.build_absolute_uri() except SuspiciousOperation: # attempt to build a URL for reporting as Django won't allow us to # use get_host() if request.is_secure(): scheme = 'https' else: scheme = 'http' host = get_host(request) uri = '%s://%s%s' % (scheme, host, request.path) rdata = None if request.method not in ('GET', 'HEAD'): try: rdata = request.body except Exception: try: rdata = request.raw_post_data except Exception: # assume we had a partial read. try: rdata = request.POST or '<unavailable>' except Exception: rdata = '<unavailable>' else: if isinstance(rdata, MultiValueDict): rdata = dict( (k, v[0] if len(v) == 1 else v) for k, v in iter(rdata.lists())) data['request'] = { 'method': request.method, 'url': uri, 'query_string': request.META.get('QUERY_STRING'), 'data': rdata, 'cookies': dict(request.COOKIES), 'headers': dict(get_headers(request.META)), 'env': dict(get_environ(request.META)), } return data
def request2crashreporting(request): """ Transform django/wsgi request object to a dict the crash reporting can understand. """ data = {} # Pieces grabbed from raven.contrib.django.client try: uri = request.build_absolute_uri() except SuspiciousOperation: # attempt to build a URL for reporting as Django won't allow us to # use get_host() if request.is_secure(): scheme = 'https' else: scheme = 'http' host = get_host(request) uri = '%s://%s%s' % (scheme, host, request.path) rdata = None if request.method not in ('GET', 'HEAD'): try: rdata = request.body except Exception: try: rdata = request.raw_post_data except Exception: # assume we had a partial read. try: rdata = request.POST or '<unavailable>' except Exception: rdata = '<unavailable>' else: if isinstance(rdata, MultiValueDict): rdata = dict((k, v[0] if len(v) == 1 else v) for k, v in iter(rdata.lists())) data['request'] = { 'method': request.method, 'url': uri, 'query_string': request.META.get('QUERY_STRING'), 'data': rdata, 'cookies': dict(request.COOKIES), 'headers': dict(get_headers(request.META)), 'env': dict(get_environ(request.META)), } return data
def get_data_from_request(self, request): result = {} user = getattr(request, 'user', None) if user is not None: user_info = self.get_user_info(user) if user_info: result['user'] = user_info try: uri = request.build_absolute_uri() except SuspiciousOperation: if request.is_secure(): scheme = 'https' else: scheme = 'http' host = get_host(request) uri = '%s://%s%s' % (scheme, host, request.path) if request.method not in ('GET', 'HEAD'): try: data = request.body except Exception: try: data = request.raw_post_data except Exception: try: data = request.POST or '<unavailable>' except Exception: data = '<unavailable>' else: data = None environ = request.META result.update({'request': {'method': request.method, 'url': uri, 'query_string': request.META.get('QUERY_STRING'), 'data': data, 'cookies': dict(request.COOKIES), 'headers': dict(get_headers(environ)), 'env': dict(get_environ(environ))}}) return result