I want to recreate this curl command using Python and requests:
curl --show-error --fail-early --user "user:pswd" --upload-file path_to_file\file.csv https://domain/REST/upload
This is a function I wrote to send the data:
# url = 'https://domain/REST/upload/file.csv' <- includes file name
def upload_file(file: Path, url: str, user: str, pswd: str) -> None:
with open(file, 'rb') as f:
response = requests.put(url, files={file.name: f},
auth=HTTPBasicAuth(user, pswd))
The response I get:
response.status_code
- 200
response.text
- OK
However the delivered CSV has some lines added to it. To be more precise it looks like this:
-- d2bba62dkvj39bccd207b6d229c4f3f2 <- How do I get
Content-Disposition: form-data; name="file.csv"; filename="file.csv" <- rid of these
<- three lines?
NAME; AGE; HEIGHT
Leslie;34; 157
Ron; 50; 179
Tom; 38; 168
April; 20; 168
<- And also
-- d2bba62dkvj39bccd207b6d229c4f3f2 <- these two...