属性错误:“响应”对象没有属性“数据”;

发布于 2025-01-09 10:59:12 字数 575 浏览 3 评论 0原文

我正在玩 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 正在工作,但不允许我将其仅与用户名隔离。

数据输出看起来像这样(小片段),我只想打印用户名

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

有什么想法吗?

I'm playing around with tweepy but I'm not sure that's the issue, maybe with my editor (Atom)?

I've successfully pulled data from the api using:

users = client.get_users_followers(id=id)

I then wish to print the data.

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

I get the error AttributeError: 'Response' object has no attribute 'data'

If I do

for user in users:
    print(user)

It prints all the data so I know the api is working, but doesn't allow me to isolate it to just the usernames.

The data output looks like this (small snippet) and I just want to print the username

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

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风尘浪孓 2025-01-16 10:59:12

删除“b”字符Python 3 中字符串文字前面

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

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

utf = user.encode('utf-8')
print(utf[0].username)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文