Python 3.x 出现连接错误。项目与电报Bot API连接

Python 3.x 出现连接错误。项目与电报Bot API连接,python-3.x,pycharm,telegram,telegram-bot,python-telegram-bot,Python 3.x,Pycharm,Telegram,Telegram Bot,Python Telegram Bot,该项目与电报Bot API连接。有人知道问题出在哪里吗 Bot需要向用户询问他想玩的游戏:Hangman或Tictatoe(它们是其他文件)。用户回答,游戏需要启动,但我没有收到来自我的机器人的任何信息。几周前我开始从事电报工作,所以我对它还很陌生 代码: 刽子手代码是: import telebot import constants bot = telebot.TeleBot(constants.token) @bot.message_handler(content_types=["sta

该项目与电报Bot API连接。有人知道问题出在哪里吗

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

代码:

刽子手代码是:

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

如果
TicTacToe
hangman
是函数,那么您需要像调用
TicTacToe()
hangman()那样调用它们

如果它们是包含函数的类,那么语法就有点不同,但是如果不发布这些模块,就很难分辨

发布这些模块会很有帮助

另一方面,根据python的PEP 8样式指南-

导入总是放在文件的顶部,就在任何模块注释和docstring之后,模块全局变量和常量之前


hangman
TicTacToe
plz添加代码。还有一个完整的错误回溯-从函数error开始查看。回溯(最近一次调用):文件“C:\Users\…\AppData\Roaming\Python\Python36\site packages\requests\packages\urllib3\connectionpool.py”,第544行,在urlopen body=body,headers=headers中,不在注释中。把这个添加到问题中好的,那是doneNo,它们是文件,我用
import hangman
import TicTacToe
调用它们。当我把
import
放在文件顶部时,它根本不起作用
import hangman
hangman
中运行代码,这就是为什么它不能在顶部运行,因为您不希望在顶部运行它。2.
import hangman
之后的行
hangman
没有影响。3.如果hangman中没有函数或类,那么我不确定为什么它不工作,因为
import-hangman
应该运行代码,但是如果有函数或类,那么它们只在
import
行中注册,而不运行,直到用
()
调用它们,就像
hangman()
那样。你能帮我把其中一个或两个的密码都发出来吗?我发得更高了8:avito 55.794673
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
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] Подключение не установлено, т.к. конечный компьютер отверг запрос на подключение