python - python请求发送带有图像和json数据的表单数据
问题描述
import json
import requests
import urllib.request as urllib2
profile_url = 'http://127.0.0.1:8000/api/user-profile/'
img_file1 = urllib2.urlopen('https://cgafrica-media.s3.eu-west-2.amazonaws.com/static/{}'.format(path_of_image))
img_file2 = urllib2.urlopen('https://cgafrica-media.s3.eu-west-2.amazonaws.com/static/{}'.format(profile_banner_path))
files=[
(('image',img_file1.read()),'image/jpeg'),
(('profile_banner',img_file2.read()), 'image/jpeg')
]
headers = {
'Content-Type': 'application/json',
'Authorization': 'token 519a585bfee6161e1f2617aa8e5be6bdeea8d5e8',
'Cookie': 'csrftoken=OLELqHA3pBRyheGuyS3zbA3RBpfZceJq5NLPXqUrZnp7KuaHWLI3etEA1UbxOf9A'
}
response = requests.request("POST", profile_url, data={"username": "soub"}, files=files)
在这里,我正在尝试使用 requests 将图像和一些数据发送到上述端点。我的图像在 aws s3 上,所以我正在阅读和发送这样的图像。这是正确的方法还是我错过了什么?
它说expected string or bytes-like object
请看一下
解决方案
推荐阅读
- reactjs - 拥有一个主应用程序,无需安装即可将迷你应用程序存储在同一个应用程序中
- java - 如何使用反射从另一个项目访问类内的枚举?
- acumatica - 在“调查屏幕”中删除记录时出错
- vue.js - 在 vue.js 的 v-for 中更改对象值 v-for
- python - 使用 pyinstaller 执行 python 3.7 时出错
- javascript - 在同一行上对齐条件渲染组件 - 材质 UI
- html - shopify主题中的模糊视频缩略图
- c++ - GetTextExtentPoint 导致别名
- angular - ngx-translate 如何将翻译文件引用映射到任何一个模块并在任何其他惰性模块中使用它们而无需多次下载
- ibm-cloud-infrastructure - 如何获取 VLAN 的网络速度