RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1203598
Accepted
Rick Petrev
Rick Petrev
Asked:2021-11-12 18:55:25 +0000 UTC2021-11-12 18:55:25 +0000 UTC 2021-11-12 18:55:25 +0000 UTC

Viber 机器人无法连接

  • 772

连接服务器上的所有证书。注册了一个机器人。我从关闭的代码。文档并上传到服务器

from flask import Flask, request, Response
from viberbot import Api
from viberbot.api.bot_configuration import BotConfiguration
from viberbot.api.messages.text_message import TextMessage
import logging

from viberbot.api.viber_requests import ViberFailedRequest
from viberbot.api.viber_requests import ViberMessageRequest
from viberbot.api.viber_requests import ViberSubscribedRequest

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)

app = Flask(__name__)
viber = Api(BotConfiguration(
    name='имя',
    avatar='https://dl-media.viber.com/5/share/2/long/vibes/icon/image/0x0/130b/87c64fe73f29f2601d0f2243c4be524f688e45be0a64abbc11d479fefc1b130b.jpg',
    auth_token='токен'
))
viber.set_webhook("https://сайт:4443/bots/viber/")



@app.route('/', methods=['POST'])
def incoming():
    logger.debug("received request. post data: {0}".format(request.get_data()))
    # every viber message is signed, you can verify the signature using this method
    if not viber.verify_signature(request.get_data(), request.headers.get('X-Viber-Content-Signature')):
        return Response(status=403)

    # this library supplies a simple way to receive a request object
    viber_request = viber.parse_request(request.get_data())

    if isinstance(viber_request, ViberMessageRequest):
        message = viber_request.message
        # lets echo back
        viber.send_messages(viber_request.sender.id, [
            message
        ])
    elif isinstance(viber_request, ViberSubscribedRequest):
        viber.send_messages(viber_request.get_user.id, [
            TextMessage(text="thanks for subscribing!")
        ])
    elif isinstance(viber_request, ViberFailedRequest):
        logger.warn("client failed receiving message. failure: {0}".format(viber_request))

    return Response(status=200)

if __name__ == "__main__":
    context = ('server.crt', 'server.key')
    app.run(host='0.0.0.0', port=443, debug=True, ssl_context=context)

我收到一个错误

2020-11-12 10:40:08,864 - requests.packages.urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): chatapi.viber.com
2020-11-12 10:40:14,244 - requests.packages.urllib3.connectionpool - DEBUG - https://chatapi.viber.com:443 "POST /pa/set_webhook HTTP/1.1" 200 224
Traceback (most recent call last):
  File "webhook.py", line 24, in <module>
    viber.set_webhook("https://мойсайт:4443/bots/viber/")
  File "/usr/local/lib/python3.5/dist-packages/viberbot/api/api.py", line 29, in set_webhook
    return self._request_sender.set_webhook(url, webhook_events, is_inline)
  File "/usr/local/lib/python3.5/dist-packages/viberbot/api/api_request_sender.py", line 32, in set_webhook
    raise Exception(u"failed with status: {0}, message: {1}".format(result['status'], result['status_message']))
Exception: failed with status: 1, message: Result[HttpRequest[POST /bots/viber/ HTTP/1.1]@1b2c34c4 > HttpResponse[null 0 null]@6b5df0a3] java.util.concurrent.TimeoutException: Total timeout 5000 ms elapsed

决定添加 viber.json 文件

{
  "url": "мойсайт/bots/viber/"
}

并通过 curl 发出请求

curl -# -i -g -H "X-Viber-Auth-Token:токен" -d @viber.json -X POST https://chatapi.viber.com/pa/set_webhook -v

已收到

Warning: Couldn't read data from file "viber.json", this makes an empty POST.
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 52.44.100.16...
* TCP_NODELAY set
* Connected to chatapi.viber.com (52.44.100.16) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=*.viber.com
*  start date: Feb 13 00:00:00 2020 GMT
*  expire date: Mar 13 12:00:00 2021 GMT
*  subjectAltName: host "chatapi.viber.com" matched cert's "*.viber.com"
*  issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
*  SSL certificate verify ok.
> POST /pa/set_webhook HTTP/1.1
> Host: chatapi.viber.com
> User-Agent: curl/7.52.1
> Accept: */*
> X-Viber-Auth-Token:token
> Content-Length: 0
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< cache-control: no-cache no-store
cache-control: no-cache no-store
< content-type: application/json
content-type: application/json
< date: Thu Nov 12 05:53:32 2020
date: Thu Nov 12 05:53:32 2020
< server-time: 78wWvHUBAAA=
server-time: 78wWvHUBAAA=
< Content-Length: 73
Content-Length: 73
< Connection: keep-alive
Connection: keep-alive

<
* Curl_http_done: called premature == 0
* Connection #0 to host chatapi.viber.com left intact
{"status":4,"status_message":"missingData","chat_hostname":"SN-CHAT-03_"}

我不明白问题是什么,为什么它不启动?

python
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    Riangry
    2021-11-12T19:16:39Z2021-11-12T19:16:39Z

    您的路由有错误。您正在尝试在站点上放置一个 webhook:4443/bots/viber,并且路由仅在站点上配置:4443 也许 viber 没有收到来自服务器的响应并引发错误

    @app.route('/', methods=['POST'])
    

    用。。。来代替

    @app.route('/bots/viber', methods=['POST'])
    
    • 0

相关问题

  • 是否可以以某种方式自定义 QTabWidget?

  • telebot.anihelper.ApiException 错误

  • Python。检查一个数字是否是 3 的幂。输出 无

  • 解析多个响应

  • 交换两个数组的元素,以便它们的新内容也反转

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    如何从列表中打印最大元素(str 类型)的长度?

    • 2 个回答
  • Marko Smith

    如何在 PyQT5 中清除 QFrame 的内容

    • 1 个回答
  • Marko Smith

    如何将具有特定字符的字符串拆分为两个不同的列表?

    • 2 个回答
  • Marko Smith

    导航栏活动元素

    • 1 个回答
  • Marko Smith

    是否可以将文本放入数组中?[关闭]

    • 1 个回答
  • Marko Smith

    如何一次用多个分隔符拆分字符串?

    • 1 个回答
  • Marko Smith

    如何通过 ClassPath 创建 InputStream?

    • 2 个回答
  • Marko Smith

    在一个查询中连接多个表

    • 1 个回答
  • Marko Smith

    对列表列表中的所有值求和

    • 3 个回答
  • Marko Smith

    如何对齐 string.Format 中的列?

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5