在discord\client.py错误中对python脚本的回溯错误?

在discord\client.py错误中对python脚本的回溯错误?,python,bots,discord,Python,Bots,Discord,我无法在VisualStudio代码中正确运行任何python代码。错误消息是持久的,无论我使用什么方法访问文件,错误都会不断返回。代码如下: def read_token(): path='/path/used/to.txt' 打开(路径“r”)作为f: 行=f.read() 返回行[0]。条带() 令牌=读取令牌() 打印(令牌) 尝试: bot.run(令牌) 除discord.errors.LoginFailure外,e: 打印('登录失败,错误401') 执行此操作将在终端上输出:

我无法在VisualStudio代码中正确运行任何python代码。错误消息是持久的,无论我使用什么方法访问文件,错误都会不断返回。代码如下:

def read_token():
path='/path/used/to.txt'
打开(路径“r”)作为f:
行=f.read()
返回行[0]。条带()
令牌=读取令牌()
打印(令牌)
尝试:
bot.run(令牌)
除discord.errors.LoginFailure外,e:
打印('登录失败,错误401')
执行此操作将在终端上输出:

<function read_token at 0x7f2d0edba268>
login failed, ERROR 401 unauthorized
现在将此作为错误提供给我:

  File "/home/falwaeth/BotDev/welcomeBot.py", line 31, in <module>
    bot.run(token)
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 640, in run
    return future.result()
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 621, in runner
    await self.start(*args, **kwargs)
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 584, in start
    await self.login(*args, bot=bot)
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 442, in login
    await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'function' object has no attribute 'strip'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "/home/falwaeth/BotDev/welcomeBot.py", line 31, in <module>
    bot.run(token)
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 640, in run
    return future.result()
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 621, in runner
    await self.start(*args, **kwargs)
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 584, in start
    await self.login(*args, bot=bot)
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 442, in login
    await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'function' object has no attribute 'strip'
文件“/home/falwaeth/BotDev/welcomeBot.py”,第31行,在
bot.run(令牌)
文件“/home/falwaeth/.local/lib/python3.7/site packages/discord/client.py”,第640行,正在运行
返回future.result()
文件“/home/falwaeth/.local/lib/python3.7/site packages/discord/client.py”,第621行,在runner中
等待自我启动(*args,**kwargs)
文件“/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py”,第584行,开头
等待self.login(*args,bot=bot)
文件“/home/falwaeth/.local/lib/python3.7/site packages/discord/client.py”,第442行,登录
等待self.http.static\u登录(token.strip(),bot=bot)
AttributeError:“函数”对象没有属性“strip”
sys.excepthook中出错:
回溯(最近一次呼叫最后一次):
文件“/usr/lib/python3/dist packages/apport\u python\u hook.py”,第63行,apport\u excepthook
从apport.fileutils导入可能的\u打包,获取\u最近的\u崩溃
文件“/usr/lib/python3/dist-packages/apport/_-init___.py”,第5行,在
从apport.report导入报告
文件“/usr/lib/python3/dist-packages/apport/report.py”,第30行,在
导入apport.fileutils
文件“/usr/lib/python3/dist-packages/apport/fileutils.py”,第23行,在
从apport.packaging\u impl导入impl as packaging
文件“/usr/lib/python3/dist packages/apport/packaging_impl.py”,第24行,in
进口apt
文件“/usr/lib/python3/dist-packages/apt/_-init___.py”,第23行,在
进口apt_包装
ModuleNotFoundError:没有名为“apt_pkg”的模块
最初的例外是:
回溯(最近一次呼叫最后一次):
文件“/home/falwaeth/BotDev/welcomeBot.py”,第31行,在
bot.run(令牌)
文件“/home/falwaeth/.local/lib/python3.7/site packages/discord/client.py”,第640行,正在运行
返回future.result()
文件“/home/falwaeth/.local/lib/python3.7/site packages/discord/client.py”,第621行,在runner中
等待自我启动(*args,**kwargs)
文件“/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py”,第584行,开头
等待self.login(*args,bot=bot)
文件“/home/falwaeth/.local/lib/python3.7/site packages/discord/client.py”,第442行,登录
等待self.http.static\u登录(token.strip(),bot=bot)
AttributeError:“函数”对象没有属性“strip”
知道原因吗?

f.read()
将以字符串形式返回文件内容,因此
行[0]。strip()
将是该文件的第一个字符。我怀疑你想要这个:

path = '/path/used/to.txt'
with open(path, "r") as f:
    lines = f.readlines()
    return lines[0].strip()

你能分享你的代码吗?看起来您没有向
客户端传递字符串。运行
读取令牌
看起来可能是一个函数。你打算叫它吗
token=read_token()
i修复了这个问题,但出现了相同的错误;参见第6、7和10行的上述更改,我已经尝试了这方面的多次迭代;但是我发现了一个新问题。将编辑原始问题以反映。
  File "/home/falwaeth/BotDev/welcomeBot.py", line 31, in <module>
    bot.run(token)
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 640, in run
    return future.result()
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 621, in runner
    await self.start(*args, **kwargs)
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 584, in start
    await self.login(*args, bot=bot)
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 442, in login
    await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'function' object has no attribute 'strip'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "/home/falwaeth/BotDev/welcomeBot.py", line 31, in <module>
    bot.run(token)
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 640, in run
    return future.result()
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 621, in runner
    await self.start(*args, **kwargs)
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 584, in start
    await self.login(*args, bot=bot)
  File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 442, in login
    await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'function' object has no attribute 'strip'
path = '/path/used/to.txt'
with open(path, "r") as f:
    lines = f.readlines()
    return lines[0].strip()