python
1 if 'button_1' in request.POST: 2 import os, tempfile, zipfile 3 from wsgiref.util import FileWrapper 4 from django.conf import settings 5 import mimetypes 6 filename = "pg/Search_source.csv" # Select your file here. 7 download_name ="Search.csv" 8 wrapper = FileWrapper(open(filename)) 9 content_type = mimetypes.guess_type(filename)[0] 10 response = HttpResponse(wrapper,content_type=content_type) 11 response['Content-Length'] = os.path.getsize(filename) 12 response['Content-Disposition'] = "attachment; filename=%s"%download_name 13 return response
上記で ....pg/Search_sourceのファイルをweb上でダウンロードされるプログラムにしようとしています。
ローカルではダウンロードが完了後も終わらない(残り0%で止まる)ですが、
viewファイルを更新すると完了する。(受信完了の処理がされていない?)
リモート上だと アプリケーションエラーとなり、
ログを確認すると
log
12019-09-04T08:02:42.024494+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=POST path="/some_view/" host=****.herokuapp.com request_id=41161ac9-f1ca-487e-862e-47a03fa3e46b fwd="219.99.154.250" dyno=web.1 connect=0ms service=964ms status=503 bytes= protocol=https 22019-09-04T08:02:42.024272+00:00 app[web.1]: 10.29.107.38 - - [04/Sep/2019:17:02:42 +0900] "POST /some_view/ HTTP/1.1" 200 82 "https://****.herokuapp.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
とH18エラーが出てしまいます。
responseでエラーなのは確実と思いますが、原因がわかりません。
対応策はあるのでしょうか。
試したこと
直ぐに次に進むのでエラーになると思い、 sleepを使用 →変わらず
return response を除きローカル、リモートで実行 →共に正常 = response時にエラー
リモート = heroku
フレームワーク =django
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。