У меня есть конечная точка, с которой я загружаю изображения на s3. Теперь проблема в том, что код не работает на производственном сервере во время загрузки с локального компьютера, а тестовый сервер работает нормально. Это ошибка, которую я получаю при производстве:
Тип исключения: HTTPClientError at / v3 / file / Exception Значение: HTTP-клиент поднял и необработанное исключение: у объекта 'module' нет атрибута 'wait_for_read'
Код API:
import boto3
from hireapp.settings import AWS_S3
from django.shortcuts import render
from django.utils.crypto import get_random_string
from .serializers import AdCategorySerializer
class FileUpload(APIView):
permission_classes = (IsAuthenticated, )
def post(self, request, format=None):
img = request.data["file"]
session = boto3.Session(
aws_access_key_id=AWS_S3["AWS_ACCESS_KEY_ID"],
aws_secret_access_key=AWS_S3["AWS_SECRET_ACCESS_KEY"],
)
s3 = session.resource('s3')
image_name = get_random_string(25) + img.name
s3.Bucket(AWS_S3["AWS_STORAGE_BUCKET_NAME"]).put_object(Key='media/%s'%image_name, Body=img, ACL='public-read')
#url to image
image_url = "https://mobile.testapp.net/media/{image}".format(image=image_name)
return Response(image_url,status=status.HTTP_200_OK)
И это является частью stacktrace:
*File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/rest_framework/views.py" in dispatch
477. response = self.handle_exception(exc)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/rest_framework/views.py" in handle_exception
437. self.raise_uncaught_exception(exc)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/rest_framework/views.py" in dispatch
474. response = handler(request, *args, **kwargs)
File "/home/irongate-server/irongate-server/hireapp/v3/views.py" in post
29. s3.Bucket(AWS_S3["AWS_STORAGE_BUCKET_NAME"]).put_object(Key='media/%s'%image_name, Body=img, ACL='public-read')
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/boto3/resources/factory.py" in do_action
520. response = action(self, *args, **kwargs)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/boto3/resources/action.py" in __call__
83. response = getattr(parent.meta.client, operation_name)(**params)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/client.py" in _api_call
316. return self._make_api_call(operation_name, kwargs)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/client.py" in _make_api_call
613. operation_model, request_dict, request_context)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/client.py" in _make_request
632. return self._endpoint.make_request(operation_model, request_dict)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/endpoint.py" in make_request
102. return self._send_request(request_dict, operation_model)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/endpoint.py" in _send_request
137. success_response, exception):
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/endpoint.py" in _needs_retry
231. caught_exception=caught_exception, request_dict=request_dict)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/hooks.py" in emit
356. return self._emitter.emit(aliased_event_name, **kwargs)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/hooks.py" in emit
228. return self._emit(event_name, kwargs)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/hooks.py" in _emit
211. response = handler(**kwargs)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/retryhandler.py" in __call__
183. if self._checker(attempts, response, caught_exception):
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/retryhandler.py" in __call__
251. caught_exception)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/retryhandler.py" in _should_retry
269. return self._checker(attempt_number, response, caught_exception)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/retryhandler.py" in __call__
317. caught_exception)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/retryhandler.py" in __call__
223. attempt_number, caught_exception)
File "/home/irongate-server/irongate-server/local/lib/python2.7/site-packages/botocore/retryhandler.py" in _check_caught_exception
359. raise caught_exception*
Я не уверен, почему рабочий код не работает, когда все остальное между сервером тестирования одинаково и производственный. Если бы кто-нибудь мог помочь, я был бы благодарен. Заранее спасибо.