1
def curlDBPedia(DB_url):
    data = json.dumps({"text":"President Obama called Wednesday on Congress to extend a tax break for students included in last year's economic stimulus package, arguing that the policy provides more generous assistance.",
    "confidence": "0.2", "support": "20"
    })
    c = pycurl.Curl()
    c.setopt(pycurl.URL, DB_url)
    c.setopt(pycurl.POST, 1)
    c.setopt(pycurl.POSTFIELDS, data)
    c.perform()
curlDBPedia("http://spotlight.dbpedia.org/rest/annotate")

The program is given as above, but I can not get correct response from the server. The error is: )

com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) com.sun.grizzly.ContextTask.run(ContextTask.java:71) com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) java.lang.Thread.run(Thread.java:701) . . . .

This is only a snapshot of the error.

How can I fix it?

Wyatt
  • 1,357
  • 5
  • 17
  • 26
  • 1
    I'm a bit confused; it looks like you've pasted Python code, but a java stacktrace. Can you provide a bit more context? UPDATE: after posting that URL into a browser (which will do a GET request, I realize), I see similar output. The output isn't a stacktrace from *your* program, but the output from the server. So something in the request needs to be different. – Joshua Taylor Jun 17 '15 at 11:51
  • What does the start of the exception say? That's the important part, not the end. – svick Jun 17 '15 at 16:17
  • It looks like the web server has some bugs. – Wyatt Jun 20 '15 at 10:05

1 Answers1

3

You could try this code ..

def curlDBPedia(DB_url):
        data = json.dumps({"text":"President Obama called Wednesday on Congress to extend a tax break for students included in last year's economic stimulus package, arguing that the policy provides more generous assistance.",
        "confidence": "0.2", "support": "20"
        })
        buffer = StringIO()
        c = pycurl.Curl()
        c.setopt(pycurl.URL, DB_url)
        c.setopt(pycurl.POST, 1)
        c.setopt(pycurl.POSTFIELDS, data)
        c.setopt(c.WRITEFUNCTION, buffer.write)
        c.perform()
        c.close()
        body = buffer.getvalue()#here we got the response data
    curlDBPedia("http://spotlight.dbpedia.org/rest/annotate")
byteC0de
  • 5,153
  • 5
  • 33
  • 66