开发者

Python 2.7.1 Blogger API problem

I recently started writing a simple client using the Blogger API to do some basic posting I implemented the client in Python and used the example code verbatim from the Blogger Developer's Guide to login, get the blog id, and make a new post. I ran the script and everything went fine until I got to this line:

retu开发者_如何学编程rn blogger_service.Post(entry, '/feeds/%s/posts/default' % blog_id)

I got the error message:

Traceback (most recent call last):
  File "cs1121post.py", line 38, in <module>
    cs1121post()
  File "cs1121post.py", line 33, in cs1121post
    return blogger_service.Post(entry, '/feeds/%s/posts/default' % blog_id)
  File "/usr/local/lib/python2.7/dist-packages/gdata/service.py", line 1236, in Post
    media_source=media_source, converter=converter)
  File "/usr/local/lib/python2.7/dist-packages/gdata/service.py", line 1322, in PostOrPut
    headers=extra_headers, url_params=url_params)
  File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 93, in optional_warn_function
    return f(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/atom/service.py", line 176, in request
    content_length = CalculateDataLength(data)
  File "/usr/local/lib/python2.7/dist-packages/atom/service.py", line 736, in  CalculateDataLength
    return len(str(data))
  File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 377, in __str__
    return self.ToString()
  File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 374, in ToString
    return ElementTree.tostring(self._ToElementTree(), encoding=string_encoding)
  File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 369, in _ToElementTree
    self._AddMembersToElementTree(new_tree)
  File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 331, in _AddMembersToElementTree
    member._BecomeChildElement(tree)
  File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 357, in _BecomeChildElement
    self._AddMembersToElementTree(new_child)
  File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 342, in _AddMembersToElementTree
    ExtensionContainer._AddMembersToElementTree(self, tree)
  File "/usr/local/lib/python2.7/dist-packages/atom/__init__.py", line 224, in _AddMembersToElementTree
    tree.text = self.text.decode(MEMBER_STRING_ENCODING)
AttributeError: 'list' object has no attribute 'decode'

By which I'm taking it that ElementTree is at fault here. I installed ElementTree via

sudo python setup.py install

in case it matters. Is there some known incompatibility between ElementTree and Python v2.7.1? Has this happened to anybody else and how did you get it working? If you need any additional information, please reply to the thread. All the source code that is relevant is basically just the example code from the Developers Guide mentioned above. I haven't modified that at all (not even the variable names). Any input is greatly appreciated.


The stacktrace is actually pretty clear about this: You're calling decode() on a list instead of a tree element. Try getting the first element from the list and calling decode() on that:

firsttext = self.text[0].decode(MEMBER_STRING_ENCODING)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜