我用Angular6前端、Django1.11后端和Hadoop3.1构建web应用程序。我需要以最快的方式发送任何大小和格式的文件。我在django中的方法如下所示。对于不同格式的小文件,一切似乎都很正常。然而,当我尝试上传更大的文件时,经常会出现底部显示的错误。你能推荐用python中最快的方式发送所有格式和大小的文件吗?如果你需要更多的信息,请告诉我。提前谢谢。
def post(self, request):
key = request.META.get('HTTP_AUTHORIZATION').split()[1]
user_id = Token.objects.get(key=key).user_id
user_name = User.objects.get(id=user_id).username
upload_file(request.FILES['file'], user_name)
return Response(status=status.HTTP_201_CREATED)
def upload_file(file, user_name):
response = requests.put(url + ':9870/webhdfs/v1/user/' + str(user_name) + '/' + str(file) + '?op=CREATE&user.name=myuser&createflag=&createparent=true&overwrite=false' , data=file, headers={'content-type':'application/octet-stream'})
return response
错误:
django_1 | Internal Server Error: /cloud/
django_1 | Traceback (most recent call last):
django_1 | File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
django_1 | chunked=chunked)
django_1 | File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
django_1 | conn.request(method, url,**httplib_request_kw)
django_1 | File "/usr/local/lib/python3.6/http/client.py", line 1239, in request
django_1 | self._send_request(method, url, body, headers, encode_chunked)
django_1 | File "/usr/local/lib/python3.6/http/client.py", line 1285, in _send_request
django_1 | self.endheaders(body, encode_chunked=encode_chunked)
django_1 | File "/usr/local/lib/python3.6/http/client.py", line 1234, in endheaders
django_1 | self._send_output(message_body, encode_chunked=encode_chunked)
django_1 | File "/usr/local/lib/python3.6/http/client.py", line 1065, in _send_output
django_1 | self.send(chunk)
django_1 | File "/usr/local/lib/python3.6/http/client.py", line 986, in send
django_1 | self.sock.sendall(data)
django_1 | BrokenPipeError: [Errno 32] Broken pipe
django_1 |
django_1 | During handling of the above exception, another exception occurred:
django_1 |
django_1 | Traceback (most recent call last):
django_1 | File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 445, in send
django_1 | timeout=timeout
django_1 | File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
django_1 | _stacktrace=sys.exc_info()[2])
django_1 | File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 367, in increment
django_1 | raise six.reraise(type(error), error, _stacktrace)
django_1 | File "/usr/local/lib/python3.6/site-packages/urllib3/packages/six.py", line 685, in reraise
django_1 | raise value.with_traceback(tb)
django_1 | File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
django_1 | chunked=chunked)
django_1 | File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
django_1 | conn.request(method, url,**httplib_request_kw)
django_1 | File "/usr/local/lib/python3.6/http/client.py", line 1239, in request
django_1 | self._send_request(method, url, body, headers, encode_chunked)
django_1 | File "/usr/local/lib/python3.6/http/client.py", line 1285, in _send_request
django_1 | self.endheaders(body, encode_chunked=encode_chunked)
django_1 | File "/usr/local/lib/python3.6/http/client.py", line 1234, in endheaders
django_1 | self._send_output(message_body, encode_chunked=encode_chunked)
django_1 | File "/usr/local/lib/python3.6/http/client.py", line 1065, in _send_output
django_1 | self.send(chunk)
django_1 | File "/usr/local/lib/python3.6/http/client.py", line 986, in send
django_1 | self.sock.sendall(data)
django_1 | urllib3.exceptions.ProtocolError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))
django_1 |
django_1 | During handling of the above exception, another exception occurred:
django_1 |
django_1 | Traceback (most recent call last):
django_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
django_1 | response = get_response(request)
django_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
django_1 | response = self.process_exception_by_middleware(e, request)
django_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
django_1 | response = wrapped_callback(request, *callback_args,**callback_kwargs)
django_1 | File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
django_1 | return view_func(*args,**kwargs)
django_1 | File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
django_1 | return self.dispatch(request, *args,**kwargs)
django_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 483, in dispatch
django_1 | response = self.handle_exception(exc)
django_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 443, in handle_exception
django_1 | self.raise_uncaught_exception(exc)
django_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 480, in dispatch
django_1 | response = handler(request, *args,**kwargs)
django_1 | File "/code/backend/views.py", line 37, in post
django_1 | response = upload_file(request.FILES['file'], user_name)
django_1 | File "/code/backend/hdfs.py", line 8, in upload_file
django_1 | response = requests.put(url + ':9870/webhdfs/v1/user/' + str(user_name) + '/' + str(file) + '?op=CREATE&user.name=myuser&createflag=&createparent=true&overwrite=false' , data=file, headers={'content-type':'application/octet-stream'})
django_1 | File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 126, in put
django_1 | return request('put', url, data=data,**kwargs)
django_1 | File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 58, in request
django_1 | return session.request(method=method, url=url,**kwargs)
django_1 | File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 512, in request
django_1 | resp = self.send(prep,**send_kwargs)
django_1 | File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 622, in send
django_1 | r = adapter.send(request,**kwargs)
django_1 | File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 495, in send
django_1 | raise ConnectionError(err, request=request)
django_1 | requests.exceptions.ConnectionError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))
django_1 | [20/Sep/2018 18:00:59] "POST /cloud/ HTTP/1.1" 500 17134
django_1 | [20/Sep/2018 18:00:59] "GET /cloud/ HTTP/1.1" 200 591
暂无答案!
目前还没有任何答案,快来回答吧!