1

Python 3.6.4 (32 bit x86) using slackclient locally connects to the RTM API and is able to listen in on slack channel changes. That same code running in Azure (64 bit AMD) does not work.

I've made sure that the Azure python install is as close to my local machine as possible. There are a few package discrepancies (see below) though this should not be the issue since these are not being used:

Azure vs. Local Machine
* numpy 1.15.3 vs. numpy 1.16.0
* pyodbc 4.0.24 vs. pyodbc 4.0.25
* pytz 2018.7 vs. pytz 2018.9
* setuptools 38.5.2 vs. setuptools 28.8.0

I've looked at the following links though I am not sure they will help. Some of the instructions for setting up a proxy in Azure are no longer valid (off by several steps). Recently Azure stopped serving a web app of mine (C#/ASP) when I changed the (totally unrelated Python) setting below.

Application settings->General settings->Python version (from Off to 3.4)

It was a real pain to get it back. I think that I will need a proxy though I would imagine Azure should provide better instructions for this. I am somewhat of an Azure newb though not new enough to start changing things willy nilly!

make Python 3.x Slack (slackclient) use a corporate proxy

Custom Slack Bot cannot connect

https://learn.microsoft.com/en-us/azure/active-directory/manage-apps/application-proxy-configure-connectors-with-proxy-servers

https://learn.microsoft.com/en-us/azure/azure-functions/functions-proxies

import time, logging, os
from slackclient import SlackClient
from datetime import datetime

def main():
    #proxies = dict(https="proxy.azure.com:443", http="proxy.azure.com:443")
    sc = SlackClient(BOT_TOKEN)
    CHANNEL_ID = "some channel id"
    logger.debug("Listening to channel '{0}' with id '{1}' for the following actions: ".format(CHANNEL_NAME, CHANNEL_ID))

    if sc.rtm_connect():
        logger.debug("Connected to Slack!")

        while True:
            # Read latest messages
            # If activity is in CHANNEL_ID do something

    else:
        logger.debug("Couldn't connect to slack")

On my local machine I get the following (I cut out some of the code):

DEBUG - Listening to channel 'news' with id 'CFDQ3BXYZ' for the following actions:
DEBUG - message_replied
DEBUG - message_deleted
DEBUG - message_changed
DEBUG - Connected to Slack!

However, in Azure, I get the following:

DEBUG - Listening to channel 'news' with id 'CFDQ3BXYZ' for the following actions:
DEBUG - message_replied
DEBUG - message_deleted
DEBUG - message_changed
DEBUG - Couldn't connect to Slack!

The Azure error message is as follows:

01-14-2019 23:17:26, urllib3.connectionpool, DEBUG, Starting new HTTPS connection (1): slack.com:443
01-14-2019 23:17:26, urllib3.connectionpool, DEBUG, https://slack.com:443 "POST /api/rtm.start HTTP/1.1" 200 18349
01-14-2019 23:17:26, slackclient.client, WARNING, Failed RTM connect
Traceback (most recent call last):
  File "D:\home\python364x64\lib\site-packages\slackclient\server.py", line 192, in connect_slack_websocket
    http_proxy_auth=proxy_auth,
  File "D:\home\python364x64\lib\site-packages\websocket\_core.py", line 511, in create_connection
    websock.connect(url, **options)
  File "D:\home\python364x64\lib\site-packages\websocket\_core.py", line 220, in connect
    options.pop('socket', None))
  File "D:\home\python364x64\lib\site-packages\websocket\_http.py", line 120, in connect
    sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
  File "D:\home\python364x64\lib\site-packages\websocket\_http.py", line 164, in _open_socket
    sock.setsockopt(*opts)
OSError: [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\home\python364x64\lib\site-packages\slackclient\client.py", line 140, in rtm_connect
    self.server.rtm_connect(use_rtm_start=with_team_state, **kwargs)
  File "D:\home\python364x64\lib\site-packages\slackclient\server.py", line 159, in rtm_connect
    self.connect_slack_websocket(self.ws_url)
  File "D:\home\python364x64\lib\site-packages\slackclient\server.py", line 200, in connect_slack_websocket
    raise SlackConnectionError(message=str(e))
slackclient.server.SlackConnectionError: [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
01-14-2019 23:17:26, Slack_bot_listener, DEBUG, Couldn't connect to slack

Any help will be greatly appreciated!

ghbcode
  • 61
  • 1
  • 6
  • The issue boils down to the websocket.create_connection( 'wss://cerberus-xxxx.lb.slack-msgs.com/websocket/, proxy_host, proxy_port, proxy_auth) call where all of the proxy info is empty. Empty credentials work in my local machine but not in Azure. – ghbcode Jan 16 '19 at 06:49

1 Answers1

0

It appears that WebJobs are restricted to port 80 only. So there is no way to open up ports, etc. on Azure WebJobs at least at this time (see article/post below). So it appears that a VM or some other route is the way to proceed.

Can I open ports on Azure Websites?

ghbcode
  • 61
  • 1
  • 6