【问题标题】:AttributeError: 'Response' object has no attribute 'data'AttributeError:“响应”对象没有属性“数据”
【发布时间】:2022-02-23 21:33:43
【问题描述】:

我正在玩 tweepy,但我不确定这是问题所在,也许是我的编辑器 (Atom)?

我已经成功地从 api 中提取了数据,使用:

users = client.get_users_followers(id=id)

然后我想打印数据。

for user in users.data:
    print(user.username)

我收到错误 AttributeError: 'Response' object has no attribute 'data'

如果我这样做

for user in users:
    print(user)

它会打印所有数据,因此我知道 api 正在工作,但不允许我将其隔离为仅用户名。

数据输出是这样的(小sn-p),我只想打印用户名

b'{"data":[{"id":"737596418123124736","name":"Gary Surridge","username":"LordSurridge"}

有什么想法吗?

【问题讨论】:

    标签: python atom-editor tweepy


    【解决方案1】:

    Remove 'b' character do in front of a string literal in Python 3

    utf = user.encode('utf-8')
    print(utf[0].username)
    

    【讨论】:

    • 嗨。谢谢你,但它并没有解决问题。我也不确定为什么当我用谷歌搜索 twitter api 时这对其他人来说不是问题
    猜你喜欢
    • 2014-04-20
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多