【问题标题】:TypeError: 'module' object is not callable py 3TypeError:“模块”对象不可调用py 3
【发布时间】:2021-12-24 02:12:01
【问题描述】:

我正在尝试让我的 discord 机器人在 replit 时保持在线。我制作了一个名为

的新文件

keep_alive.py

下面是我输入的代码

import flask
import _thread

app = flask.Flask('Keep Alive')

@app.route('/')
def home():
    return "I'm alive"

def run():
  app.run(host='0.0.0.0',port=8080)

def keep_alive():
    t = _thread(target=run)
    t.start()

我不确定我需要更正什么。

【问题讨论】:

  • 你能告诉我们错误吗?
  • 回溯(最近一次调用最后):文件“main.py”,第 44 行,在 keep_alive() 文件“/home/runner/Gravity-Bot/keep_alive.py”,行14、在keep_alive t = _thread(target=run) TypeError: 'module' object is not callable

标签: python python-3.x discord discord.py


【解决方案1】:

替换

import _thread
#and
t = _thread(target=run)

与

from threading import Thread
#and
server = Thread(target=run)

错误是因为您试图调用模块本身。

【讨论】:

  • 非常感谢❤
  • @K.Arie np :) 你能把这个答案标记为正确吗?
猜你喜欢
  • 2022-01-03
  • 1970-01-01
  • 2017-06-17
  • 2014-09-21
  • 2011-05-30
  • 2021-11-22
相关资源
最近更新 更多