Converting A Curl To Python Requests


Answer :

You have this utility:


https://curl.trillworks.com/


I use it all the time. An example is attached. enter image description here



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:-)



Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable