2017-08-27 44 views
0

我使用python-telegram-bot構建了一個電報機器人,我想將它連接到Web鉤子。當我運行它,它給了我一個錯誤:電報機器人 - 請求地址在其上下文中無效

Exception in thread updater: 
Traceback (most recent call last): 
    File "G:\python2.7.9\lib\threading.py", line 810, in __bootstrap_inner 
    self.run() 
    File "G:\python2.7.9\lib\threading.py", line 763, in run 
    self.__target(*self.__args, **self.__kwargs) 
    File "G:\python2.7.9\lib\site-packages\telegram\ext\updater.py", line  133, in _thread_wrapper 
    target(*args, **kwargs) 
    File "G:\python2.7.9\lib\site-packages\telegram\ext\updater.py", line 319, in _start_webhook 
    self.bot) 
    File "G:\python2.7.9\lib\site-packages\telegram\utils\webhookhandler.py", line 28, in __init__ 
    super(WebhookServer, self).__init__(server_address, RequestHandlerClass) 
    File "G:\python2.7.9\lib\SocketServer.py", line 420, in __init__ 
    self.server_bind() 
    File "G:\python2.7.9\lib\BaseHTTPServer.py", line 108, in server_bind 
    SocketServer.TCPServer.server_bind(self) 
    File "G:\python2.7.9\lib\SocketServer.py", line 434, in server_bind 
    self.socket.bind(self.server_address) 
    File "G:\python2.7.9\lib\socket.py", line 224, in meth 
    return getattr(self._sock,name)(*args) 
error: [Errno 10049] The requested address is not valid in its context 

我想電報機器人連接到使用網絡掛接方法的服務器,但它給我一個錯誤。

我的代碼:

# -*- coding: utf-8 -*- 
import os 
from telegram.ext import Updater, MessageHandler, Filters 
import re                               


def delete_method(bot, update): 
    if not update.message.text: 
     print("it does not contain text") 
     return 

    mlist=[u"سلام", u"شاد"] 


    for i in mlist: 
     if re.search(i, update.message.text): 
      bot.delete_message(chat_id=update.message.chat_id, message_id=update.message.message_id) 


def main(): 
    TOKEN = "TOKEN" 
    PORT = int(os.environ.get('PORT', '5000')) 
    updater = Updater(TOKEN) 
    updater.start_webhook(listen="0.0.0.0", port=PORT, url_path=TOKEN) 
    updater.bot.set_webhook("https://my account.herokuapp.com/" + TOKEN) 
    dispatcher = updater.dispatcher 
    dispatcher.add_handler(MessageHandler(Filters.all, delete_method)) 


    updater.start_polling() 

    updater.idle() 

if __name__ == '__main__': 
    main() 
# for exit 
# updater.idle() 

你知道機器人連接到非網絡掛接方法等服務器的方法是什麼?請解釋。

+0

開始在你的URL'的https空間:故意//我的帳戶....'? – tobifasc

+0

@tobifascI不明白請解釋 – Sajjad

回答

0

因爲設置webhook並不是一件重複的事情,我建議您手動執行並節省您的時間以解決更復雜的問題。只需在下面的鏈接中替換bot-token和script-url並在瀏覽器上運行即可。

https://api.telegram.org/botBOT-TOKEN/setwebhook?url=Script-URL 

記住,你應該SCRIPT_URL以https

相關問題