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.
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
Post a Comment