发生连接错误。项目已与 Telegram Bot 连接 API

ConnectionError occurred. Project is connected with Telegram Bot API

ERROR - TeleBot: "ConnectionError occurred, args=(ProtocolError('Connection 
aborted.', ConnectionRefusedError(10061, 'Подключение не установлено, т.к. 
конечный компьютер отверг запрос на подключение', None, 10061, None)),)

该项目已连接到 Telegram Bot API。有人知道问题出在哪里吗?

Bot 需要向用户询问他想玩的游戏:Hangman 或 TicTacToe(它们是其他文件)。用户回答并且游戏需要开始,但我没有收到任何来自我的机器人的信息。几周前我开始使用 Telegram,所以我对它还很陌生。

代码:

import telebot
import constants

bot = telebot.TeleBot(constants.token)

@bot.message_handler(content_types=["start"])
def start(m):
    keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
    keyboard.add(*[types.KeyboardButton(name) for name in ['Hangman', 'Tic Tac Toe']])
    msg = bot.send_message(m.chat.id, 'What do you choose?',
        reply_markup=keyboard)
    bot.register_next_step_handler(msg, name)

def name(m):
    if m.text == 'Hangman':
        import hangman
        hangman
    elif m.text == 'Tic Tac Toe':
        import TicTacToe
        TicTacToe

bot.polling()

刽子手代码是:

PICS = ['''

  _____
  |   |
      |
      |
      |
      |
~~~~~~~~''','''

  _____
  |   |
  O   |
      |
      |
      |
~~~~~~~~''','''

  _____
  |   |
  O   |
  |   |
      |
      |
~~~~~~~~''','''

  _____
  |   |
  O   |
 /|   |
      |
      |
~~~~~~~~''','''

  _____
  |   |
  O   |
 /|\  |
      |
      |
~~~~~~~~''','''

  _____
  |   |
  O   |
 /|\  |
 /    |
      |
~~~~~~~~''','''

  _____
  |   |
  O   |
 /|\  |
 / \  |
      |
~~~~~~~~''']

keywords = 'lyceum human king guitar music chair case pencil table memes book apple phone computer program boulevard dream university physics mathematics algebra analysis geometry chemistry biology decision property grammar hedgehog progress'.split()

import random

def Random(list):
    i = random.randint(0, len(list) - 1)
    return list[i]

def Again():
        print('Again? (yes/no)')
        inp = input().lower()
        if inp == 'yes':
            return True
        else:
            return False

def Info(PICS, wrong, right, keyword):
    print(PICS[len(wrong)])
    print()
    print('Wrong letters:', end=' ')
    for letter in wrong:
        print(letter, end=' ')
    print()
    print('Word:', end = ' ')
    star = '*' * len(keyword)
    for j in range(len(keyword)):
        if keyword[j] in right:
            star = star[:j] + keyword[j] + star[j+1:]
    for letter in star:
        print(letter, end=' ')
    print()

def Done(doneword):
    while True:
        print('Put a letter:')
        word = input().lower()
        if word in doneword:
            print ('You have tried this one. Choose another letter')
        elif word not in 'mnbvcxzlkjhgfdsapoiuytrewq':
            print('Please, put a small latin letter')
        elif len(word) != 1:
            print('Your letter:')
        else:
            return word


#start
right = ''
wrong = ''
keyword = Random(keywords)
end = False
while True:
    Info(PICS, wrong, right, keyword)
    word = Done(wrong + right)
    if word in keyword:
        right = right + word
        all = True
        for a in range(len(keyword)):
            if keyword[a] not in right:
                all = False
                break
        if all:
            print('Win!')
            end = True
    else:
        wrong = wrong + word
        if len(wrong) == len(PICS) - 1:
            Info(PICS, wrong, right, keyword)
            print('You lose. Keyword:'+keyword+'"')
            end = True
    if end:
        if Again():
            wrong = ''
            right = ''
            end = False
            keyword = Random(keywords)
        else:
            break

游戏没有任何错误,只有 bot

Traceback (most recent call last):
  File "C:\Users\Соня\AppData\Roaming\Python\Python36\site-packages\requests\packages\urllib3\connectionpool.py", line 544, in urlopen
   body=body, headers=headers)
  File "C:\Users\Соня\AppData\Roaming\Python\Python36\site-packages\requests\packages\urllib3\connectionpool.py", line 341, in _make_request
self._validate_conn(conn)
  File "C:\Users\Соня\AppData\Roaming\Python\Python36\site-packages\requests\packages\urllib3\connectionpool.py", line 761, in _validate_conn
conn.connect()
  File "C:\Users\Соня\AppData\Roaming\Python\Python36\site-packages\requests\packages\urllib3\connection.py", line 204, in connect
conn = self._new_conn()
  File "C:\Users\Соня\AppData\Roaming\Python\Python36\site-packages\requests\packages\urllib3\connection.py", line 134, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
  File "C:\Users\Соня\AppData\Roaming\Python\Python36\site-packages\requests\packages\urllib3\util\connection.py", line 88, in create_connection
raise err
  File "C:\Users\Соня\AppData\Roaming\Python\Python36\site-packages\requests\packages\urllib3\util\connection.py", line 78, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] Подключение не установлено, т.к. конечный компьютер отверг запрос на подключение

如果 TicTacToehangman 是函数那么你需要像这样调用它们 TicTacToe()hangman()

如果它们 类 中有函数,那么语法会有点不同,但如果不 post 那些模块就很难分辨

post 那些模块会有帮助。

另一方面,根据 python 的 PEP 8 样式指南 - https://www.python.org/dev/peps/pep-0008/#imports

Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants.