标签: attributeerror

Python Flask:AttributeError:“NoneType”对象没有属性“is_active”

使用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 attributes attributeerror flask peewee

5
推荐指数
1
解决办法
2万
查看次数

Python AttributeError:NoneType 对象没有属性“close”

我正在学习 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 file attributeerror

5
推荐指数
1
解决办法
3万
查看次数

异常 AttributeError:“'NoneType' 对象没有属性 'path'”

我正在调试 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 python-2.7 try-except

5
推荐指数
1
解决办法
2万
查看次数

试图在 dict 上调用方法,得到 AttributeError: 'dict' object attribute 'update' is read-only

我不知道出了什么问题或导致错误的原因:

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)

python dictionary attributeerror

5
推荐指数
1
解决办法
6599
查看次数

带有 readPlist 和 AttributeError 的 DeprecationWarning

我正在尝试找到一种访问 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 boolean plist attributeerror

5
推荐指数
1
解决办法
5894
查看次数

AttributeError: 模块“telegram”没有属性“Bot”

我正在使用 python 并收到此错误。

  1. 输入电报
  2. telegram.Bot(token = '###############')

当我运行它时,出现:“AttributeError: module 'telegram' has no attribute 'Bot'” 任何想法如何解决这个问题?

python api attributeerror telegram

5
推荐指数
2
解决办法
1万
查看次数

AttributeError:“系列”对象没有属性“has_z”

GeoDataFrame我从 CSV 文件中获取了以下内容,并经过一些切片CRSgeometry分配

    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 转换geometrystr

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 …

attributeerror python-3.x writetofile geopandas

5
推荐指数
1
解决办法
1461
查看次数

AttributeError:模块“tensorboard”没有属性“lazy”

我有一个使用 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)

python attributeerror keras tensorflow tensorboard

5
推荐指数
1
解决办法
1万
查看次数

matplotlib.backends.backend_tkagg 引发“blit”属性错误

当我尝试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 导入,但它没有解决问题。

python matplotlib attributeerror

5
推荐指数
1
解决办法
2164
查看次数

AttributeError:“DatasetAutoFolds”对象没有属性“split”

在此输入图像描述

来自使用惊喜模块的推荐引擎的代码,我在任何地方都找不到答案。

split attributeerror collaborative-filtering

5
推荐指数
1
解决办法
5567
查看次数