0
我需要发送一个压缩的JSON文件与HTTP请求如何发送一个压缩文件,使用HTTP POST与龙卷风
def create_gzip():
with open('articoli.json', 'rb') as f_in, gzip.open('articoli.json.gz', 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
return open('articoli.json.gz', 'rb')
body = create_gzip()
headers = tornado.httputil.HTTPHeaders({"content-type": "application/zip charset=utf-8"})
request = tornado.httpclient.HTTPRequest("http://localhost:8889/variazione", method='POST', headers=headers, body=body)
http_response = http_client.fetch(request)
但是当我尝试这样做,它提供了以下错误:
TypeError: Expected bytes, unicode, or None; got <type 'file'>
如何发送文件?有办法让请求接受gzip吗?