python - 对简单 Django View 的 POST 请求(使用 gunicorn 在 Heroku 上托管)导致 H18 服务器请求中断错误

标签 python ios django heroku

我有一个简单的 Django View ,用于(非常粗略地)测试使用附加音频文件发出 POST 请求。 View 很简单:

@csrf_exempt
def create_from_audio(request):
    return HttpResponse("accepted")

但是在我的 heroku 日志中我看到:

2018-10-31T23:55:02.018787+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=POST path="/polls/create_from_audio" host=XXX request_id=e3608c6e-8c91-440a-ade4-b854e1f72f07 fwd="174.62.90.138" dyno=web.1 connect=0ms service=163ms status=503 bytes=199 protocol=https

发送请求的代码如下:

let url = URL(string:"...")!
        let session = URLSession.shared
        var request = URLRequest(url: url)
        request.httpMethod = "POST"
        request.setValue("audio/m4a", forHTTPHeaderField: "Content-Type")
        request.httpBody = data
        let task = session.dataTask(with: request) { data, response, error in
            if let error = error {
                NSLog("send error: \(error.localizedDescription)")
                self.showLoading(message: "error sending", error: true)
            } else {
                guard let response = response as? HTTPURLResponse else { return }
                NSLog("send complete, response: \(response.statusCode)")
                if let pendingMessage = self.pendingNewMessage {
                    self.conversation.messages.append(pendingMessage)
                    self.refreshUI()
                }
            }
        }
        task.resume()

(我意识到在生产环境中直接上传到 s3 会更好,但在我的例子中,我只是想测试使用准系统实现上传文件的粗略速度。)

最佳答案

我无法在 Django 中使用它。我切换到 Flask,现在它可以工作了,即使是大约 20MB 的大文件也是如此:

@app.route('/upload', methods=['POST', 'GET'])
def upload():
    if request.method == 'POST':
        print("it's a post!")
        file = request.files['file']
        file.save('inprogress.m4a')
        return 'Success'

关于python - 对简单 Django View 的 POST 请求(使用 gunicorn 在 Heroku 上托管)导致 H18 服务器请求中断错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53093565/

相关文章:

javascript - 使用本地缓存在 UIWebView 中动态加载 javascript 文件不起作用

python - Django正则表达式匹配长url

python - 无法解析余数 : '==0' from 'data.tab_nid==0'

ios - 过渡到 ARC - 发布不引发错误

iphone - iOS 自定义对话框

python - DialogFlow python API 返回空列表值

python - 到 PyQt5 'connect' 转换

django-tinymce HTMLField - 在管理中粘贴为纯文本

Python 使用了错误版本的 Numpy 模块

python - 分配给 numpy 结构化数组