Я пытаюсь вызвать веб-сервис на основе Java в коде Python, используя requests.post()
следующим образом:
endpoint = 'http://**.**.**.**:8080/MyApp/services/Services/login'
def index(request):
post = request.POST
if request.POST.get('login_button'):
qd = QueryDict(mutable=True)
qd.update(
inputPhoneNumber=request.POST.get('phone_num'),
inputPassword=request.POST.get('password')
)
messages.info(request, '{}?{}'.format(endpoint, qd.urlencode()))
response = requests.post('{}?{}'.format(endpoint, qd.urlencode()))
result = response.json()
messages.info(request, result)
return render(request, 'login/index.html')
Однако прокси блокирует мой запрос.Я подозреваю, что это происходит потому, что веб-сервис использует протокол http
.После 30 часов поисков я не смог найти ничего, чтобы решить эту проблему.Я попытался изменить http
на https
, но это вызвало еще одну ошибку.Для справки, я могу получить доступ к URL веб-службы Мануэлем в браузере, но не могу, в Django.Трассировка стека:
ProxyError at /login/
Request Method: POST
Request URL: http://localhost:8000/login/
Django Version: 2.2.3
Python Version: 3.7.3
Installed Applications:
['login',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware']
Traceback:
File "C:\Program Files\Python37\lib\site-packages\urllib3\connection.py" in _new_conn
160. (self._dns_host, self.port), self.timeout, **extra_kw)
File "C:\Program Files\Python37\lib\site-packages\urllib3\util\connection.py" in create_connection
80. raise err
File "C:\Program Files\Python37\lib\site-packages\urllib3\util\connection.py" in create_connection
70. sock.connect(sa)
During handling of the above exception ([WinError 10060] Bağlanılan uygun olarak belli bir süre içinde yanıt vermediğinden veya kurulan
bağlantı bağlanılan ana bilgisayar yanıt vermediğinden bir bağlantı kurulamadı), another exception occurred:
File "C:\Program Files\Python37\lib\site-packages\urllib3\connectionpool.py" in urlopen
603. chunked=chunked)
File "C:\Program Files\Python37\lib\site-packages\urllib3\connectionpool.py" in _make_request
355. conn.request(method, url, **httplib_request_kw)
File "C:\Program Files\Python37\lib\http\client.py" in request
1229. self._send_request(method, url, body, headers, encode_chunked)
File "C:\Program Files\Python37\lib\http\client.py" in _send_request
1275. self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Program Files\Python37\lib\http\client.py" in endheaders
1224. self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Program Files\Python37\lib\http\client.py" in _send_output
1016. self.send(msg)
File "C:\Program Files\Python37\lib\http\client.py" in send
956. self.connect()
File "C:\Program Files\Python37\lib\site-packages\urllib3\connection.py" in connect
183. conn = self._new_conn()
File "C:\Program Files\Python37\lib\site-packages\urllib3\connection.py" in _new_conn
169. self, "Failed to establish a new connection: %s" % e)
During handling of the above exception (<urllib3.connection.HTTPConnection object at 0x00000242A09F43C8>: Failed to establish a new connection: [WinError 10060] Bağlanılan uygun olarak belli bir süre içinde yanıt vermediğinden veya kurulan
bağlantı bağlanılan ana bilgisayar yanıt vermediğinden bir bağlantı kurulamadı), another exception occurred:
File "C:\Program Files\Python37\lib\site-packages\requests\adapters.py" in send
449. timeout=timeout
File "C:\Program Files\Python37\lib\site-packages\urllib3\connectionpool.py" in urlopen
641. _stacktrace=sys.exc_info()[2])
File "C:\Program Files\Python37\lib\site-packages\urllib3\util\retry.py" in increment
399. raise MaxRetryError(_pool, url, error or ResponseError(cause))
During handling of the above exception (HTTPConnectionPool(host='***.**.***.***', port=80): Max retries exceeded with url: http://**.**.**.**:8080/MyApp/services/Services/login?inputPhoneNumber=214123&inputPassword=321312 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000242A09F43C8>: Failed to establish a new connection: [WinError 10060] Bağlanılan uygun olarak belli bir süre içinde yanıt vermediğinden veya kurulan\r\nbağlantı bağlanılan ana bilgisayar yanıt vermediğinden bir bağlantı kurulamadı')))), another exception occurred:
File "C:\Program Files\Python37\lib\site-packages\django\core\handlers\exception.py" in inner
34. response = get_response(request)
File "C:\Program Files\Python37\lib\site-packages\django\core\handlers\base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "C:\Program Files\Python37\lib\site-packages\django\core\handlers\base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\TOLGA\Desktop\PythonWebProjects\WebLogin\login\views.py" in index
55. response = requests.post('{}?{}'.format(endpoint, qd.urlencode()))
File "C:\Program Files\Python37\lib\site-packages\requests\api.py" in post
116. return request('post', url, data=data, json=json, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\requests\api.py" in request
60. return session.request(method=method, url=url, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\requests\sessions.py" in request
533. resp = self.send(prep, **send_kwargs)
File "C:\Program Files\Python37\lib\site-packages\requests\sessions.py" in send
646. r = adapter.send(request, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\requests\adapters.py" in send
510. raise ProxyError(e, request=request)
Exception Type: ProxyError at /login/
Exception Value: HTTPConnectionPool(host='***.**.***.***', port=80): Max retries exceeded with url: http://**.**.**.**:8080/MyApp/services/Services/login?inputPhoneNumber=214123&inputPassword=321312 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000242A09F43C8>: Failed to establish a new connection: [WinError 10060] Bağlanılan uygun olarak belli bir süre içinde yanıt vermediğinden veya kurulan\r\nbağlantı bağlanılan ana bilgisayar yanıt vermediğinden bir bağlantı kurulamadı')))