将 curl 转换为 python 请求

Converting a curl to python requests

我想将以下 CURL 请求转换为 python POST 请求 所以我可以将它与请求库一起使用

curl -uadmin:AP31vzchw5mYTkB1u3DhjLT9Txj -T <PATH_TO_FILE> "http://MyArtifactory-Server/artifactory/OurRepo/<TARGET_FILE_PATH>"

在这种情况下有人可以帮忙吗?

您的案例涉及的两个方面是authentication and file uploading,具体可以参考链接。如果需要,还可以使用下面的转换代码:

#!/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()

希望对您有所帮助:-)

您拥有此实用程序:

https://curl.trillworks.com/

我一直在用它。附上一个例子。