【发布时间】:2017-07-12 17:28:27
【问题描述】:
我已经搜索了几天并试图自己解决问题,但没有成功。
我发现可以使用类似这样的方式(在 Rest Request 中发送)将文件附加到 QC Run(使用 Python 或 Ruby):
内容示例:
headers = {'accept': 'application/xml', 'Content-Type': 'multipart/form-data; boundary=exampleboundary'}
--exampleboundary
Content-Disposition: form-data; name="filename"
example.txt
--exampleboundary
Content-Disposition: form-data; name="description"
Here is the text that describes example.txt
--exampleboundary
Content-Disposition: form-data; name="file"; filename="example.txt"
Content-Type: text/plain
ContentOfFile
--exampleboundary--
这确实有效,但(显然)仅适用于文本文件 (.txt)。我真的需要上传一些图片,比如测试证据/截图。
我怎样才能做到这一点?谁能帮我解决这个问题?
我正在发送这样的请求内容:
import requests
#login
response = requests.get("http://"+server+"/qcbin/authentication-point/authenticate", auth=(user,pwd))
# Get ALM token in dict format
token = response.cookies.get_dict()
requests.post(url, content, cookies=token, headers=headers_image)
谢谢。
【问题讨论】:
-
您只需要根据您要上传的文件类型更改Content-Type
-
@Barney 对于图像(png 和 jpg),我可以使用哪种内容类型?文件的内容应该以字节为单位?你能举个例子吗?我会很感激的。谢谢。
-
github.com/macroking/ALM-Integration/blob/master/…参考upload_result_file函数
-
@Barney 是的。而已。工作完美。非常感谢。
标签: python rest attachment alm hp-quality-center