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 = <Server address>
with open("image.jpg", "rb") as image_file:
files = {'file': image_file}
auth = ('<Key>', '<Pass>')
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
<Response [200]>
{
"status": "success",
"uploaded": [
{
"filename": "image.jpg",
"id": "6476edfa1d262ad81181d992da78149d"
}
]
}
--------------
{u'id': u'6476edfa1d262ad81181d992da78149d', u'filename': u'image.jpg'}
See Question&Answers more detail:os