I want to convert my folowing CURL request to a python POST requests so I can use it with the requests library
curl -uadmin:AP31vzchw5mYTkB1u3DhjLT9Txj -T <PATH_TO_FILE> "http://MyArtifactory-Server/artifactory/OurRepo/<TARGET_FILE_PATH>"
Can anyone help in this case ?
In Python, cURL transfers requests and data to and from servers using PycURL. PycURL functions as an interface for the libcURL library within Python. Almost every programming language can use REST APIs to access an endpoint hosted on a web server.
Open POSTMAN. Click on "import" tab on the upper left side. Select the Raw Text option and paste your cURL command. Hit import and you will have the command in your Postman builder!
'cURL' is a command-line tool that lets you transmit HTTP requests and receive responses from the command line or a shell script. It is available for Linux distributions, Mac OS X, and Windows. To use cURL to run your REST web API call, use the cURL command syntax to construct the command.
You have this utility:
https://curl.trillworks.com/
I use it all the time. An example is attached.
The two aspects involved in your case is authentication and file uploading, you can refer to the links for more details. And also with the converted code below if you want it:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from requests.auth import HTTPBasicAuth
def upload_file():
username = 'admin'
password = 'AP31vzchw5mYTkB1u3DhjLT9Txj'
source_file = "<your source file"
upload_url = "http://<your server>/<your path>"
files = {'file': open(source_file, 'rb')}
requests.post(upload_url, auth=HTTPBasicAuth(username, password), files=files)
if __name__ == "__main__":
upload_file()
Hope this helps:-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With