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嗎?