首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python & pylast - AttributeError:'encode‘对象没有’encode‘python属性

Python & pylast - AttributeError:'encode‘对象没有’encode‘python属性
EN

Stack Overflow用户
提问于 2013-01-31 00:57:32
回答 2查看 2K关注 0票数 1

我是一个刚开始学习Python的新手。我尝试使用Last.fm的pylast库来拉取用户邻居的列表&他们的一些属性,但是当我试图打印邻居的国家时,我得到了以下错误:

代码语言:javascript
复制
thrillofme
None
0
Traceback (most recent call last):
  File "/Users/Moi/DSR/Week 2/My tutorials/my-lastfm-thing-3.py", line 24, in <module>
    print country
  File "/Library/Python/2.7/site-packages/pylast.py", line 944, in r
    return _string(funct(*args))
  File "/Library/Python/2.7/site-packages/pylast.py", line 3497, in _string
return text.encode("utf-8")
AttributeError: 'NoneType' object has no attribute 'encode'

看一下这个错误消息的其他解决方案,我得到的印象是country编码不正确,无法打印,但我不知道该怎么办。任何帮助都将不胜感激!这是我的代码。

代码语言:javascript
复制
import pylast

api_key = "XXX"
username = "Strangelove"
network = pylast.LastFMNetwork(api_key = api_key)
user = pylast.User(username, network)

# Let's pull a list of the specified user's Last.fm neighbours.
# Neighbours are users with a similar taste in music.

neighbours = user.get_neighbours()

for i in neighbours:
    gender = i.get_gender()
    age = i.get_age()
    country = i.get_country()
    print i
    print gender
    print age
    print country
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-31 01:06:17

缺少国家/地区名称,但pylast库未正确处理大小写。您必须自己测试是否存在空的国家/地区情况:

代码语言:javascript
复制
if country.name:
    print country
票数 2
EN

Stack Overflow用户

发布于 2014-03-01 19:03:55

我已经在我的fork of pylast中修复了这个问题。

调用country = i.get_country()时,它现在返回None,而不是Country对象,其中nameNone

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14609467

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档