简体   繁体   English

无法从flask_httpauth导入HTTPTokenAuth

[英]Trouble importing HTTPTokenAuth from flask_httpauth

I am trying to use token authentication for a Flask project. 我正在尝试对Flask项目使用令牌身份验证。

from flask_httpauth import HTTPBasicAuth # works
from flask_httpauth import HTTPTokenAuth # does not work.

I get the following error 我收到以下错误

ImportError: cannot import name HTTPTokenAuth

I tried 我试过了

pip install flask_httpauth --upgrade

But it claims everything is up to date. 但是它声称一切都是最新的。 (Flask-HTTPAuth==3.1.1) (烧瓶-HTTPAuth == 3.1.1)

The docs suggest this is the proper way to import it, but for some reason it is not working. 文档建议这是导入它的正确方法,但是由于某些原因它无法正常工作。 Any ideas how I can get the token auth to import? 有什么想法可以让我导入令牌认证吗?

Edit:: I deleted and recreated the virtual environment I was using. 编辑::我删除并重新创建了我正在使用的虚拟环境。

I am using python anywhere. 我在任何地方都使用python。

The problem persists. 问题仍然存在。 I discovered an older version of Flask_httpauth is loaded by default (v2.2.0 instead of v3.1.1). 我发现默认情况下会加载旧版本的Flask_httpauth(v2.2.0而不是v3.1.1)。 I went into the site packages and saw the HTTPTokenAuth is there and should be called. 我进入了站点包,并看到了HTTPTokenAuth,应该调用它。

I tried doing 我试着做

import flask_httpauth
print (flask_httpauth.__version__)

to check the version being called by my app, but that doesnt work for all python packages, and it seems flask_httpauth doesnt have that functionality. 检查我的应用程序正在调用的版本,但这不适用于所有python软件包,而且flask_httpauth似乎没有该功能。

There are no errors displayed where I have the virtual enviorment linked on the web tab of pythonanywhere. 在pythonanywhere的Web选项卡上链接了虚拟环境的位置没有显示任何错误。

PythonAnywhere dev here, just reposting the solution that was discovered from @ExperimentsWithCode's forum post . 这里的PythonAnywhere开发人员,只是重新发布了从@ExperimentsWithCode的论坛帖子中发现的解决方案。 The problem was happening when the code was being run from the editor on PythonAnywhere. 从PythonAnywhere上的编辑器运行代码时,发生了问题。 This is separate from the configuration that is done on the "Web" tab where the virtualenv was specified: people can run any code they want from the editor, regardless of which web app it's associated with, or even code that's not associated with a web app. 这与在其中指定virtualenv的“ Web”选项卡上进行的配置是分开的:人们可以从编辑器中运行他们想要的任何代码,而不管它与哪个Web应用程序相关,甚至与该Web应用程序无关。应用程序。

So the solution was what @Miguel suggested: use a shebang. 因此解决方案就是@Miguel所建议的:使用shebang。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM