使用slackclient的Python 3.6.4(32位x86)在本地连接到RTM API,并且能够侦听松弛通道的更改。在Azure(64位AMD)中运行的相同代码不起作用。
我已确保Azure python安装尽可能靠近我的本地计算机。软件包之间存在一些差异(请参见下文),尽管这并不是问题,因为未使用它们:
Azure与本地计算机
* numpy 1.15.3与numpy 1.16.0
* Pyodbc 4.0.24与Pyodbc 4.0.25
* pytz 2018.7与pytz 2018.9
* setuptools 38.5.2与setuptools 28.8.0
我不确定以下链接是否会有所帮助。在Azure中设置代理的某些说明不再有效(需要执行几个步骤)。最近,当我更改了以下(完全不相关的Python)设置时,Azure停止提供我的Web应用程序(C#/ ASP)。
Application settings->General settings->Python version (from Off to 3.4)
找回它真的很痛苦。我认为我需要一个代理,尽管我想Azure应该为此提供更好的说明。我有点像Azure的新手,尽管还不够新,无法开始改变一切!
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")
在我的本地计算机上,我得到以下内容(我剪切了一些代码):
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!
但是,在Azure中,我得到以下信息:
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!
Azure错误消息如下:
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
任何帮助将不胜感激!
答案 0 :(得分:0)
似乎WebJobs仅限于端口80。因此,至少目前没有办法在Azure WebJobs上打开端口等(请参阅下面的文章/发布)。因此看来,VM或其他路由是继续的方法。