Query Stardog over HTTP

3 views
Skip to first unread message

James Chen

unread,
Apr 3, 2014, 12:54:22 PM4/3/14
to sta...@clarkparsia.com
Hi all

I'm trying to set up a very simple HTTP python query to my Stardog database but have been banging my head against the wall for 2 days now.  I have a DB set up called CompHawkDB using the default security settings (user: admin, pass: admin)

Here's the code I'm using:

import requests
import urllib.parse

headers = {
    'SD-Query-Bindings': '',
    'SD-Connection-String': '',
}

query = {'query' : 'SELECT ?s WHERE { ?s ?p ?o .}'}
request_url = 'http://localhost:5820/CompHawkDB/query?' + urllib.parse.urlencode(query)
print(request_url)
r = requests.get(request_url, headers=headers, auth=('admin', 'admin'))

print(r.status_code)
print(r.headers)
print(r.text)

But when I run this code I get the following output:

http://localhost:5820/CompHawkDB/query?query=SELECT+%3Fs+WHERE+%7B+%3Fs+%3Fp+%3Fo+.%7D
400
CaseInsensitiveDict({'server': 'Stardog/2.1.2/v4', 'content-length': '52'})
A JSONObject text must begin with '{' at character 0

If I change the request_url to the size line then the code runs just fine:

http://localhost:5820/CompHawkDB/size
200
CaseInsensitiveDict({'content-encoding': 'gzip', 'content-type': 'text/plain', 'transfer-encoding': 'chunked'})
44972

Can anyone here help me out?  I've tried adding more header fields like "Accept" and "Content-Type" but they all come back with the same problem:(
  1. What is wrong with the way that I'm doing the query?
  2. How come 'SD-Error-Code' is not returned as part of the header in either cases?
Thanks in advance!

James

Mike Grove

unread,
Apr 3, 2014, 1:28:32 PM4/3/14
to stardog
You're sending the query bindings header, but not including any bindings, so when the server is trying to make sure they are JSON, it's failing to parse.  If you remove the empty header, you should be fine.  We'll make it handle this a bit more gracefully in the next release.
 
  1. How come 'SD-Error-Code' is not returned as part of the header in either cases?
The error code it set for failure of valid requests.  In this case, the server sees invalid JSON provided as part of the request, and it's sending back a 400 to indicate that there's something wrong with the request itself.  If the failure had been during query execution, you'd see something come back in the error code.

Cheers,

Mike

 
Thanks in advance!

James

--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en

James Chen

unread,
Apr 3, 2014, 3:00:53 PM4/3/14
to sta...@clarkparsia.com
Thanks Mike, I actually just accidentally discovered that removing the empty headers worked!  It's still great to get clarifications on why it failed though:)
Reply all
Reply to author
Forward
0 new messages