I have been looking around for a few days now and cannot figure this out. Basically I'm uploading an image to a server and get an ID in return, the problem is I cannot figure out how to extract this ID and change it into a String ready to be saved into a database.
Program Code
url =
with open("image.jpg", "rb") as image_file:
files = {'file': image_file}
auth = ('', '')
r = requests.post(url, files=files, auth=auth)
data = r.json()
uploaded = data.get('uploaded')
content_id = uploaded[0]
print r
print r.text
print '--------------'
print str(content_id)
And here is the output I get
{
"status": "success",
"uploaded": [
{

本文讲述了如何使用Python的requests库上传图片到服务器,并从返回的JSON响应中提取并转化ID为字符串,以便保存到数据库。在示例代码中,解析JSON数据并获取'uploaded'列表的第一个元素的'id'字段。
最低0.47元/天 解锁文章
6303

被折叠的 条评论
为什么被折叠?



