用python从一个表里读取数据转化为text,Python请求-从response.text中提取数据

本文讲述了如何使用Python的requests库上传图片到服务器,并从返回的JSON响应中提取并转化ID为字符串,以便保存到数据库。在示例代码中,解析JSON数据并获取'uploaded'列表的第一个元素的'id'字段。
摘要由CSDN通过智能技术生成

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": [

{

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值