google-code-export / gdata-python-client

Automatically exported from code.google.com/p/gdata-python-client
1 stars 0 forks source link

Cannot create new Contact GroupEntry with Python client: ElementTree error #485

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.from 
http://code.google.com/apis/contacts/docs/3.0/developers_guide_python.html use 
the following code to create a new contact group:
new_group = gdata.contacts.data.GroupEntry(title=atom.data.Title(text='my best 
friends'))
group_entry = gd_client.CreateGroup(new_group)

What is the expected output? What do you see instead?
Nothing. On success, the new stored group should be assigned to group_entry.

I get the following traceback instead. Note, I added a simple method 
(CreateGroup) to the class in sample_contact.py which executes the 2 lines of 
code above:
Traceback (most recent call last):
  File "contacts.py", line 473, in <module>
    main()
  File "contacts.py", line 469, in main
    dest.Run()
  File "contacts.py", line 303, in Run
    self.CreateGroup()
  File "contacts.py", line 238, in CreateGroup
    group_entry = self.gd_client.CreateGroup(new_group)
  File "/usr/lib/python2.6/dist-packages/gdata/contacts/service.py", line 193, in CreateGroup
    converter=gdata.contacts.GroupEntryFromString)
  File "/usr/lib/python2.6/dist-packages/gdata/service.py", line 1236, in Post
    media_source=media_source, converter=converter)
  File "/usr/lib/python2.6/dist-packages/gdata/service.py", line 1322, in PostOrPut
    headers=extra_headers, url_params=url_params)
  File "/usr/lib/python2.6/dist-packages/atom/__init__.py", line 93, in optional_warn_function
    return f(*args, **kwargs)
  File "/usr/lib/python2.6/dist-packages/atom/service.py", line 176, in request
    content_length = CalculateDataLength(data)
  File "/usr/lib/python2.6/dist-packages/atom/service.py", line 731, in CalculateDataLength
    return len(ElementTree.tostring(data))
  File "/usr/lib/python2.6/xml/etree/ElementTree.py", line 1009, in tostring
    ElementTree(element).write(file, encoding)
  File "/usr/lib/python2.6/xml/etree/ElementTree.py", line 663, in write
    self._write(file, self._root, encoding, {})
  File "/usr/lib/python2.6/xml/etree/ElementTree.py", line 673, in _write
    items = node.items()
AttributeError: 'GroupEntry' object has no attribute 'items'

What version of the product are you using?
Ubuntu 10.04
Python2.6
gdata-2.0.13
>>> xml.etree.ElementTree.VERSION
'1.2.6'

Original issue reported on code.google.com by jay.wine...@gmail.com on 10 Jan 2011 at 5:47

GoogleCodeExporter commented 9 years ago
This appears to be affecting creating contacts as well. 

Original comment by jay.wine...@gmail.com on 10 Jan 2011 at 6:23

GoogleCodeExporter commented 9 years ago
Hello Jay,

What is the type of gd_client? According to the stack trace, you are using a 
ContactsService whereas the documentation uses ContactsClient:
http://code.google.com/apis/contacts/docs/3.0/developers_guide_python.html#AuthC
lientLogin

The ContactsService is here for backward compatibility, if you want support for 
the newest version of the Contacts API, I would suggest using ContactsClient.
There is an update sample in the repository: 
http://code.google.com/p/gdata-python-client/source/browse/samples/contacts/cont
acts_example.py

I hope this help!

Best,
Alain

Original comment by ala...@google.com on 10 Jan 2011 at 7:23

GoogleCodeExporter commented 9 years ago
Alain, indeed I didn't catch the difference between the currently packaged code 
and the V3 docs.  Getting an hg checkout with the URL you provided and 
modifying my code to use ContactsClient works.

thanks!

Original comment by jay.wine...@gmail.com on 11 Jan 2011 at 3:12

GoogleCodeExporter commented 9 years ago
I'm glad it helped!
Closing the issue.

Best,
Alain

Original comment by ala...@google.com on 11 Jan 2011 at 4:52