我想将下面的CURL请求转换为python POST请求 所以我可以将它与请求库一起使用
curl -uadmin:AP31vzchw5mYTkB1u3DhjLT9Txj -T <PATH_TO_FILE> "http://MyArtifactory-Server/artifactory/OurRepo/<TARGET_FILE_PATH>"
在这种情况下,任何人都可以提供帮助吗?
答案 0 :(得分:13)
答案 1 :(得分:5)
您的案例涉及的两个方面是authentication和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()
希望这会有所帮助: - )