mirror of
https://github.com/curlconverter/curlconverter.git
synced 2022-05-22 02:35:29 +03:00
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:
committed by
GitHub
parent
5c2f1ab054
commit
d83919e85c
2
test/fixtures/curl_commands/upload_file.sh
vendored
Normal file
2
test/fixtures/curl_commands/upload_file.sh
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# https://github.com/curlconverter/curlconverter/issues/55
|
||||
curl http://localhost:28139 --upload-file file.txt
|
||||
19
test/fixtures/python/put_with_T_option.py
generated
vendored
19
test/fixtures/python/put_with_T_option.py
generated
vendored
@@ -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
1
test/fixtures/python/read_stdin.py
generated
vendored
@@ -1,3 +1,4 @@
|
||||
import sys
|
||||
import requests
|
||||
|
||||
headers = {
|
||||
|
||||
6
test/fixtures/python/upload_file.py
generated
vendored
Normal file
6
test/fixtures/python/upload_file.py
generated
vendored
Normal 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)
|
||||
Reference in New Issue
Block a user