Import index patterns using requests.py

Hi,
I'm trying to import index patterns to Kibana.
I tried the following command from the documentation:
curl -X POST "my_username:my_password@10.2.25.209:5601/api/saved_objects/_import" -H "kbn-xsrf: true" --form file=@V:kibana\IndexPatterns\events.ndjson
and it worked perfectly, but i need to run it using python.
I have tried

files = {'file': '@' + args.kibana_index_pattern_path}
res = requests.post("http://{0}:{1}@{2}:5601/api/saved_objects/_import".format(args.elastic_username, args.elastic_password, args.kibana_host), headers={'kbn-xsrf': 'true'}, data=files)

and the same request with different combinations of the folowing headers:
headers={'kbn-xsrf': 'true', 'Content-Type': 'application/x-ndjson', 'Accept': 'application/x-ndjson'}
also tried with and without the @ in the files.

But I keep getting the same error message: {'message': 'Unsupported Media Type', 'error': 'Unsupported Media Type', 'statusCode': 415}

What is the coreect way to run this curl using python?

4 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.