When doing interface tests , There is often an interface for uploading files , I'll teach you how to use it today apipost Interface testing tools and python+requests Script for interface testing .
One 、 Use python+requests
python+requests When testing the interface of document upload , Need to call files, However, you need to pay attention to the format of the description path when reading and uploading files , because window To read a file, you can use , But it is used as an escape character in a string .
Three solutions :
1. The way of escape
'd:img.jpg'
2. Explicitly declare that the string does not need to be escaped
'd:rimg.jpg'
3. Use Linux The path of /
'd:/img.jpg'
python+requests Interface test script
Two 、 Use apipost Interface test tool for file upload
open apipost, Input url, hold body Inside text Change it to file, Select the file to upload . Click send to upload the interface file .
Interface testing tool :https://www.apipost.cn