Py学习  »  Python

Python 3.64可以连接到本地松弛(通过SLAKEclipse),但在Azure中它不能

ghbcode • 4 年前 • 259 次点击  

使用slackclient的python 3.6.4(32位x86)在本地连接到rtm api,并能够监听松弛通道的变化。在azure(64位amd)中运行的相同代码不起作用。

我已经确保azure python安装尽可能靠近我的本地计算机。有一些包装差异(见下文),但这不应成为问题,因为这些差异未被使用:

azure与本地计算机
*纽比1.15.3 vs.纽比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应该提供更好的说明。我是一个有点蔚蓝的新手,虽然还不够新,开始改变的东西任性!

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

Custom Slack Bot cannot connect

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

https://docs.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

任何帮助都将不胜感激!

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43735
 
259 次点击  
文章 [ 1 ]  |  最新文章 4 年前
ghbcode
Reply   •   1 楼
ghbcode    5 年前

似乎webjobs仅限于端口80。所以目前还没有办法打开azure webjobs上的端口等(见下面的文章/帖子)。所以看起来vm或其他路由是继续的方式。

Can I open ports on Azure Websites?