У меня есть приложение Django API, которое очищает веб-сайт с помощью питонской библиотеки RoboBrowser, которая позволяет легко входить и переходить со страницы, на которую вы перенаправлены.Скопированный код находится в файле views.py, а данные отображаются в представлении API с использованием среды REST Django.Мое приложение работало в моей локальной сети, но когда я поставил проект на heroku и попытался просмотреть представление API с данными JSON, я получил эту ошибку.
'Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
Это трассировка:
Environment:
Request Method: GET
Request URL: https://restschool.herokuapp.com/results/
Django Version: 2.1.4
Python Version: 3.6.7
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'webapp']
Installed Middleware:
('whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/connectionpool.py" in _make_request
377. httplib_response = conn.getresponse(buffering=True)
During handling of the above exception (getresponse() got an unexpected keyword argument 'buffering'), another exception occurred:
File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/connectionpool.py" in urlopen
600. chunked=chunked)
File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/connectionpool.py" in _make_request
384. six.raise_from(e, None)
File "<string>" in raise_from
File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/connectionpool.py" in _make_request
380. httplib_response = conn.getresponse()
File "/app/.heroku/python/lib/python3.6/http/client.py" in getresponse
1331. response.begin()
File "/app/.heroku/python/lib/python3.6/http/client.py" in begin
297. version, status, reason = self._read_status()
File "/app/.heroku/python/lib/python3.6/http/client.py" in _read_status
266. raise RemoteDisconnected("Remote end closed connection without"
During handling of the above exception (Remote end closed connection without response), another exception occurred:
File "/app/.heroku/python/lib/python3.6/site-packages/requests/adapters.py" in send
449. timeout=timeout
File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/connectionpool.py" in urlopen
638. _stacktrace=sys.exc_info()[2])
File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/util/retry.py" in increment
367. raise six.reraise(type(error), error, _stacktrace)
File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/packages/six.py" in reraise
685. raise value.with_traceback(tb)
File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/connectionpool.py" in urlopen
600. chunked=chunked)
File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/connectionpool.py" in _make_request
384. six.raise_from(e, None)
File "<string>" in raise_from
File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/connectionpool.py" in _make_request
380. httplib_response = conn.getresponse()
File "/app/.heroku/python/lib/python3.6/http/client.py" in getresponse
1331. response.begin()
File "/app/.heroku/python/lib/python3.6/http/client.py" in begin
297. version, status, reason = self._read_status()
File "/app/.heroku/python/lib/python3.6/http/client.py" in _read_status
266. raise RemoteDisconnected("Remote end closed connection without"
During handling of the above exception (('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))), another exception occurred:
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
126. response = self.process_exception_by_middleware(e, request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
124. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/decorators/csrf.py" in wrapped_view
54. return view_func(*args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/views.py" in dispatch
495. response = self.handle_exception(exc)
File "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/views.py" in handle_exception
455. self.raise_uncaught_exception(exc)
File "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/views.py" in dispatch
492. response = handler(request, *args, **kwargs)
File "/app/webapp/views.py" in get
25. browser.submit_form(form)
File "/app/.heroku/python/lib/python3.6/site-packages/robobrowser/browser.py" in submit_form
343. response = self.session.request(method, url, **send_args)
File "/app/.heroku/python/lib/python3.6/site-packages/requests/sessions.py" in request
533. resp = self.send(prep, **send_kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/requests/sessions.py" in send
646. r = adapter.send(request, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/requests/adapters.py" in send
498. raise ConnectionError(err, request=request)
Exception Type: ConnectionError at /results/
Exception Value: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
Это мой код views.py
</p>
<code>from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import Results
from .serializers import ResultsSerializer
from robobrowser import RoboBrowser
# instead of looping in this file, let the phone request multiple time by looping
class ResultsList(APIView):
def get(self, request):
password = request.GET.get('q', '')
url = "https://sms13.schoolsoft.se/nacka/jsp/Login.jsp"
browser = RoboBrowser()
browser.open(url)
form = browser.get_form()
form['usertype'] = "1"
form['ssusername'] = "robin.dymer"
form['sspassword'] = password
browser.submit_form(form)
soup = browser.parsed
results = soup.find(id="week_results_con_content").find("table").find_all("div", class_="heading_bold")
for i in results:
if Results.objects.filter(title=str(i)).exists():
pass
else:
Results.objects.create(title=str(i), body="None atm")
results_data = Results.objects.all()
serializer = ResultsSerializer(results_data, many=True)
return Response(serializer.data)
</code>
Как это можно исправить, чтобы соскочить с веб-сайта heroku?