+ if o.scheme == 'https':
+ sslctx = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH)
+ sslctx.check_hostname = True
+ sslctx.verify_mode = ssl.CERT_REQUIRED
+ sslctx.load_default_certs()
+ conn = http.client.HTTPSConnection(o.netloc, context=sslctx)
+ else:
+ conn = http.client.HTTPConnection(o.netloc)
+
+ try:
+ return post_data(conn, o.path, callback_data)
+ except ssl.SSLCertVerificationError as e:
+ logger.info('post data except: {}'.format(e))
+ if 'self signed' in str(e):
+ sslctx = ssl.create_default_context(
+ purpose=ssl.Purpose.SERVER_AUTH)
+ smo_ca_path = config.get_smo_ca_config_path()
+ sslctx.load_verify_locations(smo_ca_path)
+ sslctx.check_hostname = False
+ sslctx.verify_mode = ssl.CERT_REQUIRED
+ conn = http.client.HTTPSConnection(o.netloc, context=sslctx)
+ return post_data(conn, o.path, callback_data)
+ except Exception as e:
+ logger.info('except: {}'.format(e))
+ return False
+
+
+def post_data(conn, path, data):