Can I POST data with python requests lib with http-gzip or deflate compression?

后端 未结 5 1772
深忆病人
深忆病人 2021-02-13 03:39

I use the request-module of python 2.7 to post a bigger chunk of data to a service I can\'t change. Since the data is mostly text, it is large but would compress quite well. The

5条回答
  •  情话喂你
    2021-02-13 04:39

    # Works if backend supports gzip
    
    additional_headers['content-encoding'] = 'gzip'
    request_body = zlib.compress(json.dumps(post_data))
    r = requests.post('http://post.example.url', data=request_body, headers=additional_headers)
    

提交回复
热议问题