【问题标题】:Equivalent request command for this curl此 curl 的等效请求命令
【发布时间】:2018-12-15 05:46:29
【问题描述】:

我有一个 curl 命令,它工作正常并将文件上传到服务器。

curl -v <url> --fail --user <username>:<password> --upload-file filename

我已经在 python 中尝试了 requests 模块。我发出的命令是

fileobj = open('dist\\test.zip', 'rb')
requests.put(__url, data={"upload": "upload"}, files={"archive": ("test.zip", fileobj)}, auth=HTTPBasicAuth(username,password))

python 请求不起作用并返回Bad Request、error 400。

什么是等效的python命令?

【问题讨论】:

    标签: python curl file-upload upload python-requests


    【解决方案1】:

    我能够找到解决问题的方法。

    zip_file = open(os.path.join(root, file), 'rb')
    headers = {'content-type': 'application/zip'}
    return_val = requests.put(url=url, data=zip_file, auth=HTTPBasicAuth(username, password),headers=header_type)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多