【发布时间】:2018-06-08 02:04:38
【问题描述】:
我正在尝试使用 python 和 gdata 库将照片添加到谷歌联系人。
contact = gd_client.GetContact('http://www.google.com/m8/feeds/contacts/denisz.pol%40gmail.com/base/61839cbb8a335dbb')
gd_client.ChangePhoto('img.jpeg',contact)
但是有一个错误:
AttributeError Traceback (most recent call last)
<ipython-input-62-03d065010e8f> in <module>()
----> 1 gd_client.ChangePhoto('img.jpeg',contact)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/gdata/contacts/client.py in change_photo(self, media, contact_entry_or_url, content_type, content_length, auth_token, **kwargs)
253 ifmatch_header = None
254 if isinstance(contact_entry_or_url, gdata.contacts.data.ContactEntry):
--> 255 photo_link = contact_entry_or_url.GetPhotoLink()
256 uri = photo_link.href
257 ifmatch_header = atom.client.CustomHeaders(
AttributeError: 'NoneType' object has no attribute 'href'
如果我“手动”将照片添加到联系人,一切都不会改变。
我做错了什么?
【问题讨论】:
-
contact_entry_or_url.GetPhotoLink()正在返回None,因此photo_link设置为None。因此photo_link.href会导致该错误。我不熟悉您使用的框架,但可以尝试使用gd_client.AddPhoto('img.jpeg',contact)而不是gd_client.ChangePhoto('img.jpeg',contact)。 -
@Ollie 没有功能
AddPhoto
标签: python google-app-engine google-api google-contacts-api