Python请求发送带有数据的图像

时间:2020-02-09 09:40:42

标签: python json post python-requests

我需要从客户端图像和一些数据(例如该图像的位置-> x,y)发送到服务器,但是没有任何作用。

headers = {'Content-Type': 'application/json'}
url = 'http://localhost:9886/images'
payload = {"username" : "Root", "role" : "Admin",
           "image" : open('path_to_file/image.pgm', 'rb')}
payload_json = json.dumps(payload)
r = requests.post(url, data = payload_json, headers = headers)

有人在回答一个简单的问题吗?

1 个答案:

答案 0 :(得分:0)

files = {'upload_file':open('file.txt','rb')}

r = requests.post(URL,files = files)