【问题标题】:gdata AttributeError: 'ContactEntry' object has no attribute 'name'gdata AttributeError:“ContactEntry”对象没有属性“名称”
【发布时间】:2013-10-25 03:40:01
【问题描述】:

使用 GData Python 库,版本 2.0.18

尝试使用服务方法(而不是示例应用程序中的客户端)检索联系人列表。看起来返回被映射到一个 ContactEntry(好),但是当我尝试访问 name 属性时它给出了错误:

AttributeError: 'ContactEntry' 对象没有属性 'name'

from gdata.contacts.service import ContactsService
(...)
        self.client = ContactsService(source='appname', additional_headers=additional_headers )
        feed = self.client.GetContactsFeed(uri=query.ToUri())

self.client 是一个 gdata.contacts.service

GetContactsFeed 使用

def GetContactsFeed(self, uri=None):
    uri = uri or self.GetFeedUri()
    return self.Get(uri, converter=gdata.contacts.ContactsFeedFromString)

示例代码使用desired_class=gdata.contacts.data.ContactsFeed

似乎应该有一个名称属性。 我的语法错了吗?

【问题讨论】:

标签: python gdata gdata-api google-shared-contacts google-profiles-api


【解决方案1】:

好的,这是 python 联系人示例与我的实现的问题: 在 gdata/sample/contacts/contacts_example.py 中,它使用 gdata.contacts.Client (它的长链)要求原子类使用desired_class=gdata.contacts.data.ContactsFeed。 正如问题中所指出的,该服务使用converter=gdata.contacts.ContactsFeedFromString
该转换器来自初始化文件 src/gdata/contacts/init.py,类定义也是如此。显然,此时,您知道会发生什么——初始化程序中的 xml 类与数据文件中的类不匹配。 我将这些缺失的、不正确的添加到初始化程序中,并且事情按预期工作。或者,更改为使用 desired_class 也可以(有时您必须映射到转换器...在 service.py 中不直接支持),或者将转换器添加到 data.ContactsFeed 等。

希望这对某人有所帮助。

【讨论】:

    猜你喜欢
    • 2021-07-16
    • 1970-01-01
    • 2018-12-17
    • 2013-04-06
    • 2017-05-30
    • 1970-01-01
    • 2019-03-10
    • 2018-09-23
    • 1970-01-01
    相关资源
    最近更新 更多