safer error handling
This commit is contained in:
parent
fa5de8ab39
commit
11e6419a34
1 changed files with 26 additions and 23 deletions
|
@ -96,7 +96,6 @@ class Connector():
|
|||
self.login()
|
||||
|
||||
def login(self):
|
||||
try:
|
||||
logger.debug('connecting to eventman at %s' % self.login_url)
|
||||
self.session = requests.Session()
|
||||
self.session.verify = False
|
||||
|
@ -114,9 +113,6 @@ class Connector():
|
|||
req.raise_for_status()
|
||||
req.connection.close()
|
||||
logger.info('connection to eventman at %s established' % self.login_url)
|
||||
except Exception as ex:
|
||||
logger.error('unable to connect to %s: %s' % (self.login_url, ex))
|
||||
sys.exit(1)
|
||||
|
||||
def checkin(self, code):
|
||||
msg = 'scanning code %s: ' % code
|
||||
|
@ -183,12 +179,19 @@ if __name__ == '__main__':
|
|||
cfg.read(args.config)
|
||||
if cfg['qrcode_reader'].getboolean('debug'):
|
||||
logger.setLevel(logging.DEBUG)
|
||||
try:
|
||||
connector = Connector(cfg)
|
||||
except Exception as ex:
|
||||
logger.error('unable to connect to %s: %s' % (cfg['eventman']['url'], ex))
|
||||
sys.exit(1)
|
||||
if args.code:
|
||||
connector.checkin(args.code)
|
||||
else:
|
||||
try:
|
||||
for code in scan(port=cfg['connection']['port']):
|
||||
try:
|
||||
connector.checkin(code)
|
||||
except Exception as ex:
|
||||
logger.error('error at checkin for code %s: %s', code, ex)
|
||||
except KeyboardInterrupt:
|
||||
logger.info('exiting...')
|
||||
|
|
Loading…
Reference in a new issue