Python&pylast AttributeError:“NoneType”对象没有属性“encode”Python

2024-10-01 15:34:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我是个十足的傻瓜,刚刚开始学习Python。我在玩皮拉斯特图书馆姓氏.fm要提取用户邻居的列表及其某些属性,但当我尝试打印邻居的国家/地区时,会出现以下错误:

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没有正确编码以打印,但我不太清楚该怎么做。任何帮助将不胜感激!这是我的密码。在

^{pr2}$

Tags: inpystringreturnpackages错误linelibrary
2条回答

缺少国家名称,但pylast库没有正确处理该情况。你得自己测试一下空的国家案例:

if country.name:
    print country

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

当您调用country = i.get_country()时,它现在返回None,而不是Country对象,其中name是{}。在

相关问题 更多 >

    热门问题