python - 将 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 下指定的文档,但没有帮助。有什么建议么。
解决方案
推荐阅读
- vba - MS Access中ListBox控件和case语句的正确用法是什么
- ruby - 有人可以在厨师模板中解释这段代码吗
- python - 如何永久更改字典中的值
- firebase - 访问 Firestore 所需的项目 ID 错误
- amazon-web-services - 如果我在 AWS EC2 上打开一个公共端口以运行 slackbot,是否存在任何安全问题
- c# - 输入字符串的格式不正确,流畅的验证
- r - R - 一次替换和删除数据框或多列中的第一个和最后一个百分位数
- python-3.x - Python3多个等号在同一行
- javascript - 在谷歌地图街景API中标记地点类型
- bash - 为什么 echo "abc\r\c" 和 echo "abc\rc\c" && sleep 1 在 bash 中的行为不同?