Загрузка файла

Description

Загрузка файла в python 3. Для второго поставить requests модуль

Snippet code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import requests
import os
 
function send_data_to_server(image_path, temperature):
         
    image_filename = os.path.basename(image_path)
 
    multipart_form_data = {
        'image': (image_filename, open(image_path, 'rb')),
        'temperature': ('', str(temperature)),
    }
 
    response = requests.post('http://www.example.com/api/v1/sensor_data/',
                             files=multipart_form_data)
 
    print(response.status_code)