I'm a registered user with Dydra and trying to update a repository programmatically in it. Even though I have logged in, I get a 401 error when trying to update a repository. Following is my code:
username = 'myUsername'
password = 'myPassword'
URL = 'http://dydra.com/login'
with requests.Session() as s:
resp = s.get(URL)
soup = BeautifulSoup(resp.text)
csrfToken = soup.find('meta',{'name':'csrf-token'}).get('content')
# print csrf_token
payload = {
'account[login]':username,
'account[password]':password,
'csrfmiddlewaretoken':csrfToken,
'next':'/'
}
print payload
p = s.post(URL,data=payload, headers=dict(Referer=URL))
print p.text
r = s.get('http://dydra.com/myUsername/repoName/sparql')
print r.text
for stmt in dataGraph:
dydraSparqlEndpoint = 'http://dydra.com/myUsername/repoName/sparql'
queryStringUpload = 'INSERT DATA {%s %s %s}' % stmt
sparql = SPARQLWrapper(dydraSparqlEndpoint)
sparql.setQuery(queryStringUpload)
sparql.method = 'POST'
sparql.query()
The code before the for statement works as expected. Why then is the insert statement causing an authentication error? What do I need to change in the code to successfully log in?