前提・実現したいこと
owasp broken web applicationのページ内容を取得したい
発生している問題・エラーメッセージ
TimeoutError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/urllib3/connection.py in _new_conn(self)
159 conn = connection.create_connection(
--> 160 (self._dns_host, self.port), self.timeout, **extra_kw
161 )
18 frames
/usr/local/lib/python3.6/dist-packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
83 if err is not None:
---> 84 raise err
85
/usr/local/lib/python3.6/dist-packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
73 sock.bind(source_address)
---> 74 sock.connect(sa)
75 return sock
TimeoutError: [Errno 110] Connection timed out
During handling of the above exception, another exception occurred:
NewConnectionError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
676 headers=headers,
--> 677 chunked=chunked,
678 )
/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
391 else:
--> 392 conn.request(method, url, **httplib_request_kw)
393
/usr/lib/python3.6/http/client.py in request(self, method, url, body, headers, encode_chunked)
1263 """Send a complete request to the server."""
-> 1264 self._send_request(method, url, body, headers, encode_chunked)
1265
/usr/lib/python3.6/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
1309 body = _encode(body, 'body')
-> 1310 self.endheaders(body, encode_chunked=encode_chunked)
1311
/usr/lib/python3.6/http/client.py in endheaders(self, message_body, encode_chunked)
1258 raise CannotSendHeader()
-> 1259 self._send_output(message_body, encode_chunked=encode_chunked)
1260
/usr/lib/python3.6/http/client.py in _send_output(self, message_body, encode_chunked)
1037 del self._buffer[:]
-> 1038 self.send(msg)
1039
/usr/lib/python3.6/http/client.py in send(self, data)
975 if self.auto_open:
--> 976 self.connect()
977 else:
/usr/local/lib/python3.6/dist-packages/urllib3/connection.py in connect(self)
186 def connect(self):
--> 187 conn = self._new_conn()
188 self._prepare_conn(conn)
/usr/local/lib/python3.6/dist-packages/urllib3/connection.py in _new_conn(self)
171 raise NewConnectionError(
--> 172 self, "Failed to establish a new connection: %s" % e
173 )
NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f8371621208>: Failed to establish a new connection: [Errno 110] Connection timed out
During handling of the above exception, another exception occurred:
MaxRetryError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
448 retries=self.max_retries,
--> 449 timeout=timeout
450 )
/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
724 retries = retries.increment(
--> 725 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
726 )
/usr/local/lib/python3.6/dist-packages/urllib3/util/retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
438 if new_retry.is_exhausted():
--> 439 raise MaxRetryError(_pool, url, error or ResponseError(cause))
440
MaxRetryError: HTTPConnectionPool(host='192.168.56.101', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f8371621208>: Failed to establish a new connection: [Errno 110] Connection timed out',))
During handling of the above exception, another exception occurred:
ConnectionError Traceback (most recent call last)
<ipython-input-7-8864a8f2ff25> in <module>()
1 session = HTMLSession()
2 session.headers.update({'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36'})
----> 3 r = session.get("http://192.168.56.101/")
/usr/local/lib/python3.6/dist-packages/requests/sessions.py in get(self, url, **kwargs)
541
542 kwargs.setdefault('allow_redirects', True)
--> 543 return self.request('GET', url, **kwargs)
544
545 def options(self, url, **kwargs):
/usr/local/lib/python3.6/dist-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
528 }
529 send_kwargs.update(settings)
--> 530 resp = self.send(prep, **send_kwargs)
531
532 return resp
/usr/local/lib/python3.6/dist-packages/requests/sessions.py in send(self, request, **kwargs)
641
642 # Send the request
--> 643 r = adapter.send(request, **kwargs)
644
645 # Total elapsed time of the request (approximately)
/usr/local/lib/python3.6/dist-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
514 raise SSLError(e, request=request)
515
--> 516 raise ConnectionError(e, request=request)
517
518 except ClosedPoolError as e:
ConnectionError: HTTPConnectionPool(host='192.168.56.101', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f8371621208>: Failed to establish a new connection: [Errno 110] Connection timed out',))
該当のソースコード
python
1from requests import Request, Session 2 3session = Session() 4obj_request = Request("GET", "http://192.168.56.101/") 5obj_prepped = session.prepare_request(obj_request) 6obj_response = session.send(obj_prepped, 7 verify=True, 8 timeout=60 9 )
試したこと
・Sessionの代わりにrequest-htmlのHTMLSessionを使いました
・送信するリクエストのヘッダを変更しました
session.headers.update({'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36'})
以上の変更では結果は変わらなかったです。
・以下のコードでseleniumのchromedriverを試してみました
from selenium import webdriver
from bs4 import BeautifulSoup
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver',options=options)
driver.get("http://192.168.56.101/")
print(driver.current_url) #出力は「http://192.168.56.101/」
soup = BeautifulSoup(driver.page_source)
エラーは出ませんでしたが、soupの中身は「<html><head></head><body></body></html>」のみとなっていました。
ちなみに自分のブラウザから直接OWASPにアクセスすると問題なくページが表示されます。
補足情報(FW/ツールのバージョンなど)
実行環境
環境:google colaboratory
Python:Python 3.6.9
OS:Windows10
プロキシ:有効にしていない
回答1件
あなたの回答
tips
プレビュー