Python 我们可以批量发送json对象吗?

Python 我们可以批量发送json对象吗?,python,json,python-requests,Python,Json,Python Requests,我有一个大的JSON,我需要以1MB的批量发送它。我怎样才能在python中做到这一点??。感谢您的帮助 这是密码 值是整个大JSON for key, value in attributeJs.iteritems() : data = value headers = {'Content-Type' : 'application/json'} try:

我有一个大的JSON,我需要以1MB的批量发送它。我怎样才能在python中做到这一点??。感谢您的帮助

这是密码

值是整个大JSON

for key, value in attributeJs.iteritems() :
                data = value
                headers = {'Content-Type' : 'application/json'}
                try:
                        requests.packages.urllib3.disable_warnings()
                        r = requests.post(url=URL_ATTRIBUTE, headers=headers, verify=False, data=data, timeout=(15,20))

您可以使用


您可以尝试使用区块编码请求,将数据作为生成器发送,如下所示:

def generator():
    for key, value in attributeJs.iteritems():
        yield value

headers = {'Content-Type' : 'application/json',
           'Transfer-encoding':'chunked'}

requests.packages.urllib3.disable_warnings()
r = requests.post(url=URL_ATTRIBUTE, headers=headers, verify=False, 
data=generator(), timeout=(15,20), stream=True) 
要一次获得1MB,请执行以下操作:

r.iter_content(chunk_size=1000000)  # 1MB = 1000000 Bytes
r.iter_content(chunk_size=1000000)  # 1MB = 1000000 Bytes