我在Amazon EC2实例上设置了DRF +芹菜工作者。我的主服务器在EBS上,工作人员是简单的EC2实例。
我正在尝试使用boto3包将文件上传到S3。 要上传的代码如下:
104 Connection Reset by peer
问题:
当我在本地计算机(使用本地芹菜工作者和本地服务器)上运行它时,它会上传到S3而不会出现错误。当我尝试在我的服务器工作程序实例上上传相同类型的文件作为芹菜任务时,它会引发104 connection reset by peer
错误。我不明白服务器的作用有何不同。我的本地环境与生产环境类似。
错误为broken pipe
和Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
body=body, headers=headers) File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 349, in _make_request
conn.request(method, url, **httplib_request_kw) File "/usr/lib/python3.4/http/client.py", line 1088, in request
self._send_request(method, url, body, headers) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 122, in _send_request
self, method, url, body, headers) File "/usr/lib/python3.4/http/client.py", line 1126, in _send_request
self.endheaders(body) File "/usr/lib/python3.4/http/client.py", line 1084, in endheaders
self._send_output(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 157, in _send_output
self._handle_expect_response(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 200, in _handle_expect_response
self._send_message_body(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 227, in _send_message_body
self.send(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 234, in send
return HTTPConnection.send(self, str) File "/usr/lib/python3.4/http/client.py", line 885, in send
self.sock.sendall(datablock) File "/usr/local/lib/python3.4/dist-packages/eventlet/green/ssl.py", line 170, in sendall
v = self.send(data_to_send) File "/usr/local/lib/python3.4/dist-packages/eventlet/green/ssl.py", line 145, in send
super(GreenSSLSocket, self).send, data, flags) File "/usr/local/lib/python3.4/dist-packages/eventlet/green/ssl.py", line 112, in _call_trampolining
return func(*a, **kw) File "/usr/lib/python3.4/ssl.py", line 702, in send
v = self._sslobj.write(data) ConnectionResetError: [Errno 104] Connection reset by peer During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/adapters.py", line 370, in send
timeout=timeout File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 597, in urlopen
_stacktrace=sys.exc_info()[2]) File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/packages/urllib3/util/retry.py", line 245, in increment
raise six.reraise(type(error), error, _stacktrace) File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/packages/urllib3/packages/six.py", line 309, in reraise
raise value.with_traceback(tb) File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
body=body, headers=headers) File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 349, in _make_request
conn.request(method, url, **httplib_request_kw) File "/usr/lib/python3.4/http/client.py", line 1088, in request
self._send_request(method, url, body, headers) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 122, in _send_request
self, method, url, body, headers) File "/usr/lib/python3.4/http/client.py", line 1126, in _send_request
self.endheaders(body) File "/usr/lib/python3.4/http/client.py", line 1084, in endheaders
self._send_output(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 157, in _send_output
self._handle_expect_response(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 200, in _handle_expect_response
self._send_message_body(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 227, in _send_message_body
self.send(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 234, in send
return HTTPConnection.send(self, str) File "/usr/lib/python3.4/http/client.py", line 885, in send
self.sock.sendall(datablock) File "/usr/local/lib/python3.4/dist-packages/eventlet/green/ssl.py", line 170, in sendall
v = self.send(data_to_send) File "/usr/local/lib/python3.4/dist-packages/eventlet/green/ssl.py", line 145, in send
super(GreenSSLSocket, self).send, data, flags) File "/usr/local/lib/python3.4/dist-packages/eventlet/green/ssl.py", line 112, in _call_trampolining
return func(*a, **kw) File "/usr/lib/python3.4/ssl.py", line 702, in send
v = self._sslobj.write(data) botocore.vendored.requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/ubuntu/workindia-worker/workindiaapi/Developement/api/adapter/amazons3.py", line 24, in upload
response = self.s3.Object(self.bucket_name, key).put(Body=upload_file) File "/usr/local/lib/python3.4/dist-packages/boto3/resources/factory.py", line 344, in do_action
response = action(self, *args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/boto3/resources/action.py", line 77, in __call__
response = getattr(parent.meta.client, operation_name)(**params) File "/usr/local/lib/python3.4/dist-packages/botocore/client.py", line 270, in _api_call
return self._make_api_call(operation_name, kwargs) File "/usr/local/lib/python3.4/dist-packages/botocore/client.py", line 324, in _make_api_call
operation_model, request_dict) File "/usr/local/lib/python3.4/dist-packages/botocore/endpoint.py", line 110, in make_request
return self._send_request(request_dict, operation_model) File "/usr/local/lib/python3.4/dist-packages/botocore/endpoint.py", line 139, in _send_request
success_response, exception): File "/usr/local/lib/python3.4/dist-packages/botocore/endpoint.py", line 203, in _needs_retry
caught_exception=caught_exception) File "/usr/local/lib/python3.4/dist-packages/botocore/hooks.py", line 226, in emit
return self._emit(event_name, kwargs) File "/usr/local/lib/python3.4/dist-packages/botocore/hooks.py", line 209, in _emit
response = handler(**kwargs) File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 183, in __call__
if self._checker(attempts, response, caught_exception): File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 250, in __call__
caught_exception) File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 273, in _should_retry
return self._checker(attempt_number, response, caught_exception) File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 313, in __call__
caught_exception) File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 222, in __call__
return self._check_caught_exception(attempt_number, caught_exception) File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 355, in _check_caught_exception
raise caught_exception File "/usr/local/lib/python3.4/dist-packages/botocore/endpoint.py", line 167, in _get_response
proxies=self.proxies, timeout=self.timeout) File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/sessions.py", line 573, in send
r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/adapters.py", line 415, in send
raise ConnectionError(err, request=request) botocore.vendored.requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
,如下所示:
Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
body=body, headers=headers) File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 349, in _make_request
conn.request(method, url, **httplib_request_kw) File "/usr/lib/python3.4/http/client.py", line 1088, in request
self._send_request(method, url, body, headers) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 122, in _send_request
self, method, url, body, headers) File "/usr/lib/python3.4/http/client.py", line 1126, in _send_request
self.endheaders(body) File "/usr/lib/python3.4/http/client.py", line 1084, in endheaders
self._send_output(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 157, in _send_output
self._handle_expect_response(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 200, in _handle_expect_response
self._send_message_body(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 227, in _send_message_body
self.send(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 234, in send
return HTTPConnection.send(self, str) File "/usr/lib/python3.4/http/client.py", line 885, in send
self.sock.sendall(datablock) File "/usr/local/lib/python3.4/dist-packages/eventlet/green/ssl.py", line 170, in sendall
v = self.send(data_to_send) File "/usr/local/lib/python3.4/dist-packages/eventlet/green/ssl.py", line 145, in send
super(GreenSSLSocket, self).send, data, flags) File "/usr/local/lib/python3.4/dist-packages/eventlet/green/ssl.py", line 112, in _call_trampolining
return func(*a, **kw) File "/usr/lib/python3.4/ssl.py", line 702, in send
v = self._sslobj.write(data) BrokenPipeError: [Errno 32] Broken pipe During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/adapters.py", line 370, in send
timeout=timeout File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 597, in urlopen
_stacktrace=sys.exc_info()[2]) File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/packages/urllib3/util/retry.py", line 245, in increment
raise six.reraise(type(error), error, _stacktrace) File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/packages/urllib3/packages/six.py", line 309, in reraise
raise value.with_traceback(tb) File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
body=body, headers=headers) File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 349, in _make_request
conn.request(method, url, **httplib_request_kw) File "/usr/lib/python3.4/http/client.py", line 1088, in request
self._send_request(method, url, body, headers) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 122, in _send_request
self, method, url, body, headers) File "/usr/lib/python3.4/http/client.py", line 1126, in _send_request
self.endheaders(body) File "/usr/lib/python3.4/http/client.py", line 1084, in endheaders
self._send_output(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 157, in _send_output
self._handle_expect_response(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 200, in _handle_expect_response
self._send_message_body(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 227, in _send_message_body
self.send(message_body) File "/usr/local/lib/python3.4/dist-packages/botocore/awsrequest.py", line 234, in send
return HTTPConnection.send(self, str) File "/usr/lib/python3.4/http/client.py", line 885, in send
self.sock.sendall(datablock) File "/usr/local/lib/python3.4/dist-packages/eventlet/green/ssl.py", line 170, in sendall
v = self.send(data_to_send) File "/usr/local/lib/python3.4/dist-packages/eventlet/green/ssl.py", line 145, in send
super(GreenSSLSocket, self).send, data, flags) File "/usr/local/lib/python3.4/dist-packages/eventlet/green/ssl.py", line 112, in _call_trampolining
return func(*a, **kw) File "/usr/lib/python3.4/ssl.py", line 702, in send
v = self._sslobj.write(data) botocore.vendored.requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/ubuntu/workindia-worker/workindiaapi/Developement/api/adapter/amazons3.py", line 24, in upload
response = self.s3.Object(self.bucket_name, key).put(Body=upload_file) File "/usr/local/lib/python3.4/dist-packages/boto3/resources/factory.py", line 344, in do_action
response = action(self, *args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/boto3/resources/action.py", line 77, in __call__
response = getattr(parent.meta.client, operation_name)(**params) File "/usr/local/lib/python3.4/dist-packages/botocore/client.py", line 270, in _api_call
return self._make_api_call(operation_name, kwargs) File "/usr/local/lib/python3.4/dist-packages/botocore/client.py", line 324, in _make_api_call
operation_model, request_dict) File "/usr/local/lib/python3.4/dist-packages/botocore/endpoint.py", line 110, in make_request
return self._send_request(request_dict, operation_model) File "/usr/local/lib/python3.4/dist-packages/botocore/endpoint.py", line 139, in _send_request
success_response, exception): File "/usr/local/lib/python3.4/dist-packages/botocore/endpoint.py", line 203, in _needs_retry
caught_exception=caught_exception) File "/usr/local/lib/python3.4/dist-packages/botocore/hooks.py", line 226, in emit
return self._emit(event_name, kwargs) File "/usr/local/lib/python3.4/dist-packages/botocore/hooks.py", line 209, in _emit
response = handler(**kwargs) File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 183, in __call__
if self._checker(attempts, response, caught_exception): File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 250, in __call__
caught_exception) File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 273, in _should_retry
return self._checker(attempt_number, response, caught_exception) File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 313, in __call__
caught_exception) File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 222, in __call__
return self._check_caught_exception(attempt_number, caught_exception) File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 355, in _check_caught_exception
raise caught_exception File "/usr/local/lib/python3.4/dist-packages/botocore/endpoint.py", line 167, in _get_response
proxies=self.proxies, timeout=self.timeout) File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/sessions.py", line 573, in send
r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.4/dist-packages/botocore/vendored/requests/adapters.py", line 415, in send
raise ConnectionError(err, request=request) botocore.vendored.requests.exceptions.ConnectionError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))
和
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize">
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/image_student_in_content_student_details"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/student_name_in_student_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:gravity="center"
android:text=""
android:textColor="@color/ans_post_time_color"
android:textSize="16sp" />
<TextView
android:id="@+id/student_class_in_content_student_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:text=""
android:textColor="@color/ans_post_time_color"
android:textSize="16sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:id="@+id/birthday_in_content_student_details"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_margin="10dp"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="sdf asdf asdf asdf asdf "
android:textSize="16sp" />
<TextView
android:id="@+id/sex_in_content_student_details"
android:layout_width="match_parent"
android:layout_height="50dp"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text=""
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="15dp"
android:orientation="horizontal"
android:weightSum="10">
</LinearLayout>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/blood_group_students_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:gravity="center"
android:text="Blood Group"
android:textSize="16sp"
android:visibility="gone" />
<TextView
android:id="@+id/address_students_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text=""
android:textSize="16sp" />
<TextView
android:id="@+id/email_in_content_students_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text=""
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/phone_in_content_students_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text=""
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<TextView
android:id="@+id/image_upload_student_details"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:background="@color/primary"
android:gravity="center"
android:text="Upload Image"
android:textColor="@android:color/white"
android:textSize="30sp" />
</RelativeLayout>
</ScrollView>