How to Send Files Using POST from a Python Script
Sending files using POST from a Python script is a crucial task in various applications. Fortunately, the Requests library provides an easy and efficient solution for this issue.
The following code demonstrates how to send a file named "report.xls" using POST:
<code class="python">import requests with open('report.xls', 'rb') as f: r = requests.post('http://httpbin.org/post', files={'report.xls': f})</code>
In this code, we:
The response from the server is displayed in the output, providing details about the uploaded file, including its name, size, and content type. This demonstrates that the file was successfully sent and received by the server.
Using Requests, sending files via POST from a Python script becomes a straightforward process, allowing developers to easily handle file uploads in their applications.
The above is the detailed content of How to Send Files Using POST from a Python Script with Requests?. For more information, please follow other related articles on the PHP Chinese website!