Browse Source

disabled the SSL negation settings

master
mb@mb 6 years ago
parent
commit
18282f59a6
  1. 31
      streambot.py

31
streambot.py

@ -57,7 +57,7 @@ class MUCBot(slixmpp.ClientXMPP):
# any presences you send yourself. To limit event handling
# to a single room, use the events muc::room@server::presence,
# muc::room@server::got_online, or muc::room@server::got_offline.
self.add_event_handler("muc::{}::got_online".format(self.room), self.muc_online)
# self.add_event_handler("muc::{}::got_online".format(self.room), self.muc_online)
def start(self, event):
@ -121,7 +121,13 @@ class MUCBot(slixmpp.ClientXMPP):
# publish images
if len(msg['oob']['url']) > 0:
# reply from the bot
self.send_message(mto=msg['from'].bare,
mbody="I'll stream that image further, {}.".format(msg['mucnick']),
mtype='groupchat')
# save image to folder
url = msg['oob']['url']
filename = os.path.basename(url)
targetDir = self.datadir
@ -131,19 +137,14 @@ class MUCBot(slixmpp.ClientXMPP):
targetFile = os.path.join(targetDir, filename)
# response = requests.get(url)
# if response.status_code == 200:
# with open(targetFile, 'wb') as f:
# f.write(response.content)
# needed to disable certificate validation:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
# save image to file
# urllib.request.urlretrieve(msg['oob']['url'], targetFile, context=ctx)
u = urllib.request.urlopen(url, context=ctx)
# needed to disable certificate validation, when we work in a local network:
# ctx = ssl.create_default_context()
# ctx.check_hostname = False
# ctx.verify_mode = ssl.CERT_NONE
# write image to file
# u = urllib.request.urlopen(url, context=ctx) # use this line when SSL needs to be disabled
u = urllib.request.urlopen(url)
f = open(targetFile, 'wb')
f.write(u.read())
f.close()
@ -160,6 +161,8 @@ class MUCBot(slixmpp.ClientXMPP):
# publish regular messages (only when '#publish' is used in the message)
if '#stream' in msg['body']:
# reply from the bot
self.send_message(mto=msg['from'].bare,
mbody="I'll stream that further, {}.".format(msg['mucnick']),
mtype='groupchat')

Loading…
Cancel
Save