首页 > 解决方案 > 将 cURL 请求转换为 Python2 urllib2 请求

问题描述

我正在尝试将 curl 中的以下代码转换为 python2 urllib2 请求调用以执行“PUT”操作,它适用于 cURL 但我对将其转换为 python2 代码一无所知。

卷曲

curl -X PUT -u myUser:myPassword -T test.txt “http://localhost:8081/artifactory/libs-release-local/test/test.txt”

我面临的问题是“-T”标志,我不确定如何在 urllib2 调用中设置它。我尝试通过将文件添加到 Body->form-data->file 来使用 Postman 寻求帮助

但是代码转换如下,我怀疑这不是传输文件调用。

curl -X PUT \
  http://localhost:8081/artifactory/my-repository/my/new/artifact/directory/file.txt \
  -H 'Cache-Control: no-cache' \
  -H 'Postman-Token: 4ffbfca4-a4be-09de-c8ab-0731a2d67009' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F '=@C:\Devops\file.txt'

我尝试查看 -T/--upload-file 下指定的文档,但没有帮助。有什么建议么。

https://www.computerhope.com/unix/curl.html

https://curl.haxx.se/libcurl/c/options-in-examples.html

标签: pythoncurlurllib2artifactorypython-2.6

解决方案


推荐阅读