gpt4 book ai didi

python-3.x - Python 3.6.4 可以在本地连接到 Slack(通过 slackclient),但在 Azure 中则不能

转载 作者:行者123 更新时间:2023-12-03 04:14:36 24 4
gpt4 key购买 nike

使用 slackclient 的 Python 3.6.4(32 位 x86)在本地连接到 RTM API,并且能够监听 slack channel 的变化。在 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 新手,尽管还不够新,无法随心所欲地改变事物!

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")

在我的本地计算机上,我得到以下内容(我删除了一些代码):

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

任何帮助将不胜感激!

最佳答案

看来 WebJobs 仅限于端口 80。因此,至少目前无法在 Azure WebJobs 上打开端口等(请参阅下面的文章/帖子)。因此,虚拟机或其他一些路由似乎是继续的方法。

Can I open ports on Azure Websites?

关于python-3.x - Python 3.6.4 可以在本地连接到 Slack(通过 slackclient),但在 Azure 中则不能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54194529/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com