使用Flask Mega 教程我正在尝试学习 Flask。在本教程的第 5 部分中,我现在正在构建一个需要用户登录的个人资料页面。
由于我使用 peewee ORM 而不是 SQLAlchemy,因此我确实在这里或那里调整了代码,但对于这种情况,我认为这并不重要。我现在使用我的 Google (openID) 帐户登录并遇到错误,提示AttributeError: 'NoneType' object has no attribute 'is_active'。该错误发生在该函数末尾的行中login_user(user, remember = remember_me)。
@oid.after_login
def after_login(resp):
if resp.email is None or resp.email == "":
flash('Invalid login. Please try again.')
return redirect(url_for('login'))
user = User.select().where(User.email == resp.email).first()
if user is None:
nickname = resp.nickname
if nickname is None or nickname == "":
nickname = resp.email.split('@')[0]
User(nickname = nickname, email = resp.email, role = …Run Code Online (Sandbox Code Playgroud) 我正在学习 python,我编写了一个脚本,将一个文本文件的内容复制到另一个文本文件。
这是我的代码。
from sys import argv
out_file = open(argv[2], 'w').write(open(argv[1]).read())
out_file.close()
Run Code Online (Sandbox Code Playgroud)
我得到标题上列出的 AttributeError 。为什么当我在 open(argv[2], 'w') 上调用 write 方法时,out_file 没有分配 File 类型?
先感谢您
我正在调试 python 代码(python2.7.12),因为我的代码可以工作,但是当我将推文流式传输到数据库时,所有变量都为 NULL。
我得到的错误是:
Exception AttributeError: "'NoneType' object has no attribute 'path'" in <function _remove at 0x10068f140> ignored
Run Code Online (Sandbox Code Playgroud)
我假设这个错误来自下面的代码:
def put_tweets_in_database(tweets):
print "putting tweets in database"
errors = 0
count = 0
for tweet in tweets:
try:
commit_tweet_to_database(tweet, count, len(tweets))
count += 1
except Exception as e:
print e
session.rollback()
errors += 1
print 'there were {} errors'.format(errors)
Run Code Online (Sandbox Code Playgroud)
我不认为这个功能commit_tweet_to_database()有问题...
你有什么主意吗...?我将不胜感激任何帮助!
谢谢。
我不知道出了什么问题或导致错误的原因:
AttributeError: 'dict' object attribute 'update' is read-only
Run Code Online (Sandbox Code Playgroud)
在以下代码中:
map = []
point1back = {}
point1fwd = {}
point1back.update = {'nextHop':point1Fwd, 'direction':1, 'distance':0}
point1fwd.update = {'nextHop':point1Fwd, 'direction':3, 'distance':160}
map.append(point1back)
map.append(point1fwd)
Run Code Online (Sandbox Code Playgroud) 我正在尝试找到一种访问 plist 文件的方法:/Library/Preferences/com.apple.iPod.plist 以访问其中的序列号。
这是我当前的代码--
import os
import plistlib
fileName=os.path.expanduser('/Users/Ryan/Library/Preferences/com.apple.iPod.plist')
pl=plistlib.readPlist(fileName)
for left, right in pl.items():
for values in right.values():
print(values['Serial Number'])
Run Code Online (Sandbox Code Playgroud)
我不断得到结果,但也会出现一些快速错误。我得到这个:
plist.py:8: DeprecationWarning: The readPlist function is deprecated, use load() instead pl=plistlib.readPlist(fileName)
Run Code Online (Sandbox Code Playgroud)
还有这个:
File "plist.py", line 16, in <module>
for values in right.values():
AttributeError: 'bool' object has no attribute 'values'
Run Code Online (Sandbox Code Playgroud)
我猜使用加载函数相当简单,尽管我很难使用我在网上找到的教程来弄清楚它并根据我的需要进行修改。
关于布尔属性错误,我不知道我做错了什么。
谢谢!
我正在使用 python 并收到此错误。
当我运行它时,出现:“AttributeError: module 'telegram' has no attribute 'Bot'” 任何想法如何解决这个问题?
GeoDataFrame我从 CSV 文件中获取了以下内容,并经过一些切片CRS和geometry分配
ctf_nom geometry id
0 Prunus mahaleb POINT (429125.795043319 4579664.7564311) 2616
1 Betula pendula POINT (425079.292045901 4585098.09043407) 940
2 Betula pendula POINT (425088.115045896 4585093.66943407) 940
3 Abelia triflora POINT (429116.661043325 4579685.93743111) 2002
4 Abies alba POINT (428219.962044021 4587346.66843531) 797
Run Code Online (Sandbox Code Playgroud)
我已经将 a 转换geometry为str:
from shapely import wkt
df['geometry'] = df['geometry'].apply(wkt.loads)
df_geo = gpd.GeoDataFrame(df, geometry = 'geometry')
Run Code Online (Sandbox Code Playgroud)
并通过以下方式分配了一个crs:
df_geo.crs = {'init' :'epsg:25831'}
df_geo.crs
Run Code Online (Sandbox Code Playgroud)
当我尝试再次按 gdf.to_file()函数保存减少的地理数据帧时,它返回以下属性错误:
AttributeError: 'Series' object has no …
我有一个使用 Keras 和张量流后端的生成对抗网络。我正在运行 Tensorflow 1.14.0、Python 3.7.4 和 Keras 2.2.4。完整的错误是:
Using TensorFlow backend.
Traceback (most recent call last):
File "C:/Users/Riley/PycharmProjects/shoeGAN/shoeWGAN.py", line 7, in <module>
from keras.layers import *
File "C:\Users\Riley\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\__init__.py", line 3, in <module>
from . import utils
File "C:\Users\Riley\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
from . import conv_utils
File "C:\Users\Riley\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
from .. import backend as K
File "C:\Users\Riley\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\backend\__init__.py", line 89, in <module>
from .tensorflow_backend import *
File "C:\Users\Riley\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
import tensorflow as tf
File …Run Code Online (Sandbox Code Playgroud) 当我尝试python3 module_7.py在终端上运行时,出现以下错误:
File "/opt/CarlaSimulator/PythonClient/live_plotter.py", line 227, in plot_figure
tkagg.blit(photo, fca.get_renderer()._renderer, colormode=2)
AttributeError: module 'matplotlib.backends.backend_tkagg' has no attribute 'blit'
Run Code Online (Sandbox Code Playgroud)
我检查了 matplotlib 安装,一切似乎都很好。使用CARLA模拟器时会出现此问题。有一些建议的修复方案,例如在 pyplot 导入之前添加 backend_tkagg 导入,但它没有解决问题。
attributeerror ×10
python ×7
api ×1
attributes ×1
boolean ×1
dictionary ×1
file ×1
flask ×1
geopandas ×1
keras ×1
matplotlib ×1
peewee ×1
plist ×1
python-2.7 ×1
python-3.x ×1
split ×1
telegram ×1
tensorboard ×1
tensorflow ×1
try-except ×1
writetofile ×1