This article mainly introduces the case of python requests completing the interface file upload, which has a good reference value and hopes to be helpful to everyone. Come and see Bei Fan together
Recently, I am preparing an open class. The theme is to use different languages and different tools to upload and download files.
When using Jmeter to implement functions, and when using loadrunner to write scripts, everything went smoothly without any problems. When I tried to use Python to solve this problem, it took some time.
This also allows me to find a lot of fun in learning and trying. Let me share with you how to implement the operation.
premise:
1: There is an upload interface, the address is as follows: http://xx.xx.xx.xx//upload/stream (the company's service, the address is inconvenient to send out ~ interested comrades can come to our open class!)
2: The parameters of the upload interface are as follows:
1 |
|
There are two parameters that need to be explained to you: filesize: refers to the size of the file in bytes. filename: refers to the file name you saved after uploading ~ remember not to get the suffix wrong. Other parameters can be ignored. When making the interface of your own company, you can do it according to the interface document of your own company.
Get started:
1: Install the requests module, the installation command: pip install requests
2: Send a request, the code is as follows:
1 2 3 4 |
|
View Results:
After executing the code, we can see that our upload is successful, and the effect is as follows:
If you have an interface for uploading files, please try it!
Once you learn to code, some things are a lot easier!
Supplement: Two methods for python to implement the interface to upload files
File upload: The type of uploaded image is file, header information is not used here
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
File upload: The upload type is file, and the header information is used
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
Thanks to everyone who read my article carefully, watching the rise and attention of fans all the way, there is always a need for a gift exchange, although it is not a very valuable thing, if you can use it, you can take it directly:
① More than 2000 Python e-books (mainstream and classic books should be available)
② Python standard library information (the most complete Chinese version)
③ 项目源码(四五十个有趣且经典的练手项目及源码)
④ Python基础入门、爬虫、web开发、大数据分析方面的视频(适合小白学习)
⑤ Python学习路线图(告别不入流的学习)
在我的QQ技术交流群里(技术交流和资源共享,广告进来腿给你打断)
可以自助拿走,群号913569736(备注“csdn000”)群里的免费资料都是笔者十多年测试生涯的精华。还有同行大神一起交流技术哦。
学习资料可以找到我们呢的蓓蓓小姐姐【mashang-qq】备注【csdn000】免费领取哦
【必须备注】不然不会通过哦