support --upload-file in Python generator (#382)

* support --upload-file in Python generator

* import sys

* add --upload-file to url

* update test

* handle automatically added / by URL.parse

* update test

* remove done todo
This commit is contained in:
Boris Verkhovskiy
2022-04-15 13:05:35 -07:00
committed by GitHub
parent 5c2f1ab054
commit d83919e85c
6 changed files with 71 additions and 30 deletions

View File

@@ -0,0 +1,2 @@
# https://github.com/curlconverter/curlconverter/issues/55
curl http://localhost:28139 --upload-file file.txt

View File

@@ -1,21 +1,10 @@
import requests
headers = {
# Already added when you pass json= but not when you pass data=
# 'Content-Type': 'application/json',
'Content-Type': 'application/json',
}
json_data = {
'properties': {
'email': {
'type': 'keyword',
},
},
}
with open('my_file.txt', 'rb') as f:
data = f.read()
response = requests.put('http://localhost:28139/twitter/_mapping/user?pretty', headers=headers, json=json_data)
# Note: json_data will not be serialized by requests
# exactly as it was in the original request.
#data = '{"properties": {"email": {"type": "keyword"}}}'
#response = requests.put('http://localhost:28139/twitter/_mapping/user?pretty', headers=headers, data=data)
response = requests.put('http://localhost:28139/twitter/_mapping/user?pretty', headers=headers, data=data)

1
test/fixtures/python/read_stdin.py generated vendored
View File

@@ -1,3 +1,4 @@
import sys
import requests
headers = {

6
test/fixtures/python/upload_file.py generated vendored Normal file
View File

@@ -0,0 +1,6 @@
import requests
with open('file.txt', 'rb') as f:
data = f.read()
response = requests.put('http://localhost:28139/file.txt', data=data)