SyntaxError using gdata-python-client to access Google Book Search Data API

匆匆过客 提交于 2019-12-02 02:09:42

I found I needed to disable SSL in the gdata client for it to work:

...
gd_client.ProgrammaticLogin()
gd_client.ssl = False
...

sje397's answer is the correct one; in your example above, if you do:

service.ssl = False

before running the search_by_keyword method, the result is properly returned. If you don't set SSL to be false, then because the client hasn't properly authenticated, the request is redirected to the main Google homepage (hence what Alex Martelli was seeing errors in was the HTML you get when you go to http://www.google.com ... definitely not well-formed XML).

Hacking around a bit to see the xml string, I notice it has a lowercase <!doctype html> at the start (should be uppercase DOCTYPE) which of course is making the XML parse fail -- definitely a bug in the book service which needs to be reported. As a temporary workaround you could hack the atom/__init__.xml to change line 127 to...:

tree = ElementTree.fromstring(xml_string.replace('doctype','DOCTYPE'))

but while that gets past this bug in the XML it reveals another at column 496 (I think that's in the middle of some javascript code). I guess there's something borken in bookservice in general at this point...:-(

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!