Problem:
I am trying to call a static method from a class method which throws an error. What is the right way to call that method in Python 3.x?
NameError: name 'strip_sensitive_data' is not defined Code:
import sentry_sdk from scrapy.exceptions import NotConfigured class SentryLogging(object): """ Send exceptions and errors to Sentry. """ def strip_sensitive_data(event, hint): if event['level'] == 'error': return event else: return None @classmethod def from_crawler(cls, crawler): sentry_dsn = crawler.settings.get('SENTRY_DSN', None) environment = crawler.settings.get('ENVIRONMENT', None) if sentry_dsn is None: raise NotConfigured # instantiate the extension object ext = cls() # instantiate sentry_sdk.init( sentry_dsn, traces_sample_rate=1.0, environment= environment, before_send=strip_sensitive_data ) # return the extension object return ext
SentryLogging.strip_sensitive_data. Consider also@staticmethod.cls.strip_sensitive_data?@staticmethoddecorator tostrip_sensitive_data(2) You can call it from the class, e.g.cls.strip_sensitive_data(...), or from outside of the class method you can doSentryLogging.strip_sensitive_data(...), but add the missing decorator first.