lxml - Error With AlchemyAPI Python SDK -
i trying use alchemyapi python 0.7 sdk. when ever run method within e.g. urlgettext(url);
i error:
nodes = etree.fromstring(result).xpath(xpathquery) file "lxml.etree.pyx", line 2743, in lxml.etree.fromstring (src/lxml/lxml.etree.c:52665) file "parser.pxi", line 1573, in lxml.etree._parsememorydocument (src/lxml/lxml.etree.c:79932) file "parser.pxi", line 1452, in lxml.etree._parsedoc (src/lxml/lxml.etree.c:78774) file "parser.pxi", line 960, in lxml.etree._baseparser._parsedoc (src/lxml/lxml.etree.c:75389) file "parser.pxi", line 564, in lxml.etree._parsercontext._handleparseresultdoc (src/lxml/lxml.etree.c:71739) file "parser.pxi", line 645, in lxml.etree._handleparseresult (src/lxml/lxml.etree.c:72614) file "parser.pxi", line 585, in lxml.etree._raiseparseerror (src/lxml/lxml.etree.c:71955) lxml.etree.xmlsyntaxerror: attvalue: " or ' expected, line 19, column 11
this come area of code:
def getrequest(self, apicall, apiprefix, paramobject): endpoint = 'http://' + self._hostprefix + '.alchemyapi.com/calls/' + apiprefix + '/' + apicall endpoint += '?apikey=' + self._apikey + paramobject.getparameterstring() handle = urllib.urlopen(endpoint) result = handle.read() handle.close() xpathquery = '/results/status' nodes = etree.fromstring(result).xpath(xpathquery) if nodes[0].text != "ok": raise exception, 'error making api call.' return result
any 1 have ideas going wrong?
thank you
daniel kershaw
i looked @ python urllib docs, , found page:
http://docs.python.org/library/urllib.html#high-level-interface
which contains warning filehandle
object returned urllib.urlopen()
:
one caveat: read() method, if size argument omitted or negative, may not read until end of data stream; there no way determine entire stream socket has been read in general case.
i think maybe should ensure obtain entire contents of file python string before parsing etree.fromstring()
api. like:
result = '' while (1): next = handle.read() if not next: break result += next
Comments
Post a Comment