0

I am trying to send a turtle file via a Python script using REST api to the local repository but the System is returning the following error

MALFORMED DATA: Illegal subject value: "-"^^http://www.w3.org/2001/XMLSchema#integer [line 1]

400

The used code is as follows:

import requests

url = 'http://localhost:7200/repositories/metaphactory1/statements'
with open("graph-29.ttl", "rb") as ttl_file:
    file_dict = {"graph-29.ttl" : ttl_file}
    headers = {
        "Content-type": "application/x-turtle;charset=UTF-8",
    }

    r = requests.post(url, files=file_dict, headers=headers)
    print(r.text)

    print(r.status_code)

The same file when tried with a Curl command is working fine:

 curl -X POST -H "Content-Type: application/x-turtle" -T graph-29.ttl 'http://localhost:7200/repositories/metaphactory1/statements'

Any idea regarding this issue is welcome

Gaurav
  • 37
  • 8
  • Show us graph-29.ttl, From the error it seems you have something like `"-"^^xsd:integer`. Also, the official content type is `text/turtle` – Vladimir Alexiev Feb 12 '21 at 11:45

1 Answers1

0

I think your problem come from the way you pass your file to the post request. You should try using the data parameter of the post request. For example:

import requests

url = 'http://localhost:7200/repositories/metaphactory1/statements'
file_path = '/path/to/your/file/graph-29.ttl'
graph_name = 'http://graph-29'
headers = {
  'Content-type': 'application/x-turtle',
}

params = {'graph': graph_name} #optional
response = requests.post(url, headers=headers, params=params, data=open(file_path,'r', encoding='utf-8').read())