Я пытаюсь получить доступ к публичному c API, созданному с Django Rest Framework. Это работает, но по причине, которую я еще не выяснил, я получаю следующее сообщение на Apache error.log
:
HTTP Error 400: Bad Request
и
Method Not Allowed: /api/intention
Несмотря на это , мой POST-запрос работает, но возвращение сервера не является правильным, показывая сообщение об ошибке вместо успеха, когда я нажимаю на API как приложением Android, так и непосредственно на странице DRF.
Вот мой Apache project.conf
:
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]
ServerName 127.0.0.1
ServerAlias localhost
Alias /static /path/to/project/static
<Directory /path/to/project/>
Require All Granted
</Directory>
<Directory /path/to/project/mysite/>
<Files wsgi.py>
Require all granted
</Files>
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
<Location "/">
AllowMethods GET POST PUT DELETE PATCH OPTIONS
</Location>
DocumentRoot /path/to/project
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/custom.log combined
</VirtualHost>
WSGIScriptAlias / /path/to/project/mysite/wsgi.py
WSGIPythonHome /path/to/env
WSGIPythonPath /path/to/project
WSGIPassAuthorization On
А вот модуль apache, работающий sudo apache2ctl -M
:
Loaded Modules:
.
.
.
allowmethods_module (shared)
.
.
.
РЕДАКТИРОВАТЬ
Полный файл error.log:
ubuntu@ip-10-0-30-81:/home/project/avaliei$ sudo tail -f /var/log/apache2/error.log
[Thu Mar 12 15:04:47.110372 2020] [wsgi:error] [pid 6462:tid 139737020983040] [client 170.247.239.188:41880] File "/home/project/avaliei/appraisal_flow_API/views.py", line 79, in join_intention, referer: http://ec2-18-231-89-243.sa-east-1.compute.amazonaws.com/api/intention
[Thu Mar 12 15:04:47.110376 2020] [wsgi:error] [pid 6462:tid 139737020983040] [client 170.247.239.188:41880] serializer.validated_data['phone'], referer: http://ec2-18-231-89-243.sa-east-1.compute.amazonaws.com/api/intention
[Thu Mar 12 15:04:47.110380 2020] [wsgi:error] [pid 6462:tid 139737020983040] [client 170.247.239.188:41880] File "/home/project/avaliei/appraisal_flow_API/email.py", line 23, in email_new_user_request, referer: http://ec2-18-231-89-243.sa-east-1.compute.amazonaws.com/api/intention
[Thu Mar 12 15:04:47.110384 2020] [wsgi:error] [pid 6462:tid 139737020983040] [client 170.247.239.188:41880] sg.client.mail.send.post(request_body=mail.get()), referer: http://ec2-18-231-89-243.sa-east-1.compute.amazonaws.com/api/intention
[Thu Mar 12 15:04:47.110388 2020] [wsgi:error] [pid 6462:tid 139737020983040] [client 170.247.239.188:41880] File "/home/project/env/lib/python3.6/site-packages/python_http_client/client.py", line 252, in http_request, referer: http://ec2-18-231-89-243.sa-east-1.compute.amazonaws.com/api/intention
[Thu Mar 12 15:04:47.110392 2020] [wsgi:error] [pid 6462:tid 139737020983040] [client 170.247.239.188:41880] return Response(self._make_request(opener, request, timeout=timeout)), referer: http://ec2-18-231-89-243.sa-east-1.compute.amazonaws.com/api/intention
[Thu Mar 12 15:04:47.110396 2020] [wsgi:error] [pid 6462:tid 139737020983040] [client 170.247.239.188:41880] File "/home/project/env/lib/python3.6/site-packages/python_http_client/client.py", line 176, in _make_request, referer: http://ec2-18-231-89-243.sa-east-1.compute.amazonaws.com/api/intention
[Thu Mar 12 15:04:47.110400 2020] [wsgi:error] [pid 6462:tid 139737020983040] [client 170.247.239.188:41880] raise exc, referer: http://ec2-18-231-89-243.sa-east-1.compute.amazonaws.com/api/intention
[Thu Mar 12 15:04:47.110404 2020] [wsgi:error] [pid 6462:tid 139737020983040] [client 170.247.239.188:41880] python_http_client.exceptions.BadRequestsError: HTTP Error 400: Bad Request, referer: http://ec2-18-231-89-243.sa-east-1.compute.amazonaws.com/api/intention
[Thu Mar 12 15:04:47.110409 2020] [wsgi:error] [pid 6462:tid 139737020983040] [client 170.247.239.188:41880] , referer: http://ec2-18-231-89-243.sa-east-1.compute.amazonaws.com/api/intention
Я использую Apache 2.4, Django 2.1, EC2, Ubuntu 18.04 и Python 3.6.