# Import index patterns using requests.py

**URL:** <https://discuss.elastic.co/t/import-index-patterns-using-requests-py/216767>\
**Category:** Elasticsearch\
**Created:** [January 28, 2020, 7:17am UTC](https://discuss.elastic.co/t/import-index-patterns-using-requests-py/216767 "2020-01-28T07:17:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LimorA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/limora/32/61514_2.png) [@LimorA](https://discuss.elastic.co/u/LimorA)\
**Post date:** [January 28, 2020, 7:17am UTC](https://discuss.elastic.co/t/import-index-patterns-using-requests-py/216767/1 "2020-01-28T07:17:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 25, 2020, 7:17am UTC](https://discuss.elastic.co/t/import-index-patterns-using-requests-py/216767/2 "2020-02-25T07:17:38Z")

</div>

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