将图像从URL发送到python POST请求的最佳方法

时间:2019-04-15 12:01:10

标签: python python-requests

我正在处理一个脚本,该脚本将从用户处获取产品链接,并从信息中获取该信息作为JSON主体,并提取一些必要的信息,例如

title = data['screens'][0]['meta']['default_value']['title']
desc  = data['screens'][0]['meta']['default_value']['description']
price  = data['screens'][0]['meta']['default_value']['price']
collection_id  = data['screens'][0]['meta']['default_value']['collection']['cc_id']
shipping  = data['screens'][0]['meta']['default_value']['mailing_details']
img_url = data['screens'][0]['meta']['default_value']['photos'][0]['image_url']
title -> Baby Toys product number - 1
desc  -> This is description of the product
price -> 52
collection_id -> 24
Shipping -> Free
photo_1 -> http://cdn.test.com/media/213234/cover.jpg

现在我想使用此信息将发布请求发送到另一个api

data = {
    'mailing_details': shipping,
    'multi_quantities': 'true',
    'abcpay':'false',
    'price': price,
    'description':desc,
    'title':title,
    'meetup':'false',
    'condition':'2',
    'mailing':'true',
    'collection_id':collection_id
    }

上传API

files = {'photo_1': ('img_url', 'image/jpeg')}
response = requests.request("POST", url_and,data=data,files=files,headers=headers)

现在我要做的是将图像从img_url绑定到文件dict并作为POST请求发送文件。

谢谢

0 个答案:

没有答案