gpt4 book ai didi

python / flask : TypeError: an integer is required (got type str)

转载 作者:太空狗 更新时间:2023-10-29 23:58:30 25 4
gpt4 key购买 nike

我是 python 和 flask 的新手。我正在尝试通过 http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world 上的 Flask 教程进行工作。 .我遇到了一个我无法弄清楚的错误。我已经竭尽全力(我认为)寻找解决方案,但找不到适合我问题的解决方案。我已经卸载并重新安装了 flask 。我什至创建了一个新的 venv 并重新开始,但没有任何效果。

我正在尝试构建一个简单的网络表单应用程序。我创建了一个表格,例如:

from flask_wtf import Form  
from wtforms import StringField, BooleanField
from wtforms.validators import DataRequired

class LoginForm(Form):
openid = StringField('openid', validators=[DataRequired()])
remember_me = BooleanField('remember_me', default=False)

当我导入 LoginForm 时,出现错误

TypeError: an integer is required (got type str)

完整的堆栈跟踪在这里:

C:\microblog\flask\Scripts\python.exe C:/microblog/run.py
Traceback (most recent call last):
File "C:/microblog/run.py", line 2, in <module>
from app import app
File "C:\microblog\app\__init__.py", line 6, in <module>
from app import views
File "C:\microblog\app\views.py", line 5, in <module>
from .forms import LoginForm
File "C:\microblog\app\forms.py", line 3, in <module>
from flask_wtf import Form
File "C:\microblog\flask\lib\site-packages\flask_wtf\__init__.py", line 15, in <module>
from .form import Form
File "C:\microblog\flask\lib\site-packages\flask_wtf\form.py", line 15, in <module>
from .i18n import translations
File "C:\microblog\flask\lib\site-packages\flask_wtf\i18n.py", line 12, in <module>
from flask_babel import get_locale
File "C:\microblog\flask\lib\site-packages\flask_babel\__init__.py", line 21, in <module>
from babel import dates, numbers, support, Locale
File "C:\microblog\flask\lib\site-packages\babel\dates.py", line 28, in <module>
from babel.util import UTC, LOCALTZ
File "C:\microblog\flask\lib\site-packages\babel\util.py", line 278, in <module>
from babel import localtime
File "C:\microblog\flask\lib\site-packages\babel\localtime\__init__.py", line 21, in <module>
from babel.localtime._win32 import _get_localzone
File "C:\microblog\flask\lib\site-packages\babel\localtime\_win32.py", line 18, in <module>
tz_names = get_global('windows_zone_mapping')
File "C:\microblog\flask\lib\site-packages\babel\core.py", line 58, in get_global
_global_data = pickle.load(fileobj)
TypeError: an integer is required (got type str)

感谢任何帮助 - 这让我抓狂!

最佳答案

这是 python 包索引上的 babel 2.0 包中的构建错误

https://github.com/mitsuhiko/babel/issues/174

总而言之,包中包含一个 pickled 文件 babel/global.dat,python 3 无法读取该文件,因为它是由在 python 2 下运行的脚本创建的。

我按照 github 问题中的建议,通过从 github 而不是 PyPI 安装来解决这个问题:

pip install git+https://github.com/mitsuhiko/babel.git@2.0

关于 python / flask : TypeError: an integer is required (got type str),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31708355/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com