[コードの参考サイト]
https://qiita.com/neet-AI/items/98d4194872ee4f53e3b4
[実行環境]
Python 3.7.3
Windows 10 Pro
Jupiter notebook
社内ネットワーク
python
1import requests 2response = requests.get('https://ja.wikipedia.org/wiki/%E3%83%9A%E3%83%BC%E3%82%B8') 3print(response.text)
スクレイピングの練習のため上記のコードを実行すると、下記のようなエラーが出ました。
おそらく社内のプロキシに引っかかったのだと思いますが、どうすべきか分からず苦しんでいます。
解決方法を教えていただけないでしょうか?
--------------------------------------------------------------------------- OSError Traceback (most recent call last) C:\Anaconda3\lib\site-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) 593 if is_new_proxy_conn: --> 594 self._prepare_proxy(conn) 595 C:\Anaconda3\lib\site-packages\urllib3\connectionpool.py in _prepare_proxy(self, conn) 804 conn.set_tunnel(self._proxy_host, self.port, self.proxy_headers) --> 805 conn.connect() 806 C:\Anaconda3\lib\site-packages\urllib3\connection.py in connect(self) 307 # self._tunnel_host below. --> 308 self._tunnel() 309 # Mark this connection as not reusable C:\Anaconda3\lib\http\client.py in _tunnel(self) 910 raise OSError("Tunnel connection failed: %d %s" % (code, --> 911 message.strip())) 912 while True: OSError: Tunnel connection failed: 407 Proxy Authentication Required ( Forefront TMG ã¯ãè¦æ±ãå®è¡ãã権éãè¦æ±ãã¦ãã¾ããWeb ãããã· ãã£ã«ã¿ã¼ã¸ã®ã¢ã¯ã»ã¹ã¯æå¦ããã¾ãã ) During handling of the above exception, another exception occurred: MaxRetryError Traceback (most recent call last) C:\Anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies) 448 retries=self.max_retries, --> 449 timeout=timeout 450 ) C:\Anaconda3\lib\site-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) 637 retries = retries.increment(method, url, error=e, _pool=self, --> 638 _stacktrace=sys.exc_info()[2]) 639 retries.sleep() C:\Anaconda3\lib\site-packages\urllib3\util\retry.py in increment(self, method, url, response, error, _pool, _stacktrace) 398 if new_retry.is_exhausted(): --> 399 raise MaxRetryError(_pool, url, error or ResponseError(cause)) 400 MaxRetryError: HTTPSConnectionPool(host='ja.wikipedia.org', port=443): Max retries exceeded with url: /wiki/%E3%83%9A%E3%83%BC%E3%82%B8 (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required ( Forefront TMG ã\x81¯ã\x80\x81è¦\x81æ±\x82ã\x82\x92å®\x9fè¡\x8cã\x81\x99ã\x82\x8b権é\x99\x90ã\x82\x92è¦\x81æ±\x82ã\x81\x97ã\x81¦ã\x81\x84ã\x81¾ã\x81\x99ã\x80\x82Web ã\x83\x97ã\x83\xadã\x82\xadã\x82· ã\x83\x95ã\x82£ã\x83«ã\x82¿ã\x83¼ã\x81¸ã\x81®ã\x82¢ã\x82¯ã\x82»ã\x82¹ã\x81¯æ\x8b\x92å\x90¦ã\x81\x95ã\x82\x8cã\x81¾ã\x81\x99ã\x80\x82 )'))) During handling of the above exception, another exception occurred: ProxyError Traceback (most recent call last) <ipython-input-26-1ec3f8246665> in <module> 1 import requests 2 ----> 3 req = requests.get("https://ja.wikipedia.org/wiki/%E3%83%9A%E3%83%BC%E3%82%B8") 4 print(req.text) C:\Anaconda3\lib\site-packages\requests\api.py in get(url, params, **kwargs) 73 74 kwargs.setdefault('allow_redirects', True) ---> 75 return request('get', url, params=params, **kwargs) 76 77 C:\Anaconda3\lib\site-packages\requests\api.py in request(method, url, **kwargs) 58 # cases, and look like a memory leak in others. 59 with sessions.Session() as session: ---> 60 return session.request(method=method, url=url, **kwargs) 61 62 C:\Anaconda3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 531 } 532 send_kwargs.update(settings) --> 533 resp = self.send(prep, **send_kwargs) 534 535 return resp C:\Anaconda3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs) 644 645 # Send the request --> 646 r = adapter.send(request, **kwargs) 647 648 # Total elapsed time of the request (approximately) C:\Anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies) 508 509 if isinstance(e.reason, _ProxyError): --> 510 raise ProxyError(e, request=request) 511 512 if isinstance(e.reason, _SSLError): ProxyError: HTTPSConnectionPool(host='ja.wikipedia.org', port=443): Max retries exceeded with url: /wiki/%E3%83%9A%E3%83%BC%E3%82%B8 (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required ( Forefront TMG ã\x81¯ã\x80\x81è¦\x81æ±\x82ã\x82\x92å®\x9fè¡\x8cã\x81\x99ã\x82\x8b権é\x99\x90ã\x82\x92è¦\x81æ±\x82ã\x81\x97ã\x81¦ã\x81\x84ã\x81¾ã\x81\x99ã\x80\x82Web ã\x83\x97ã\x83\xadã\x82\xadã\x82· ã\x83\x95ã\x82£ã\x83«ã\x82¿ã\x83¼ã\x81¸ã\x81®ã\x82¢ã\x82¯ã\x82»ã\x82¹ã\x81¯æ\x8b\x92å\x90¦ã\x81\x95ã\x82\x8cã\x81¾ã\x81\x99ã\x80\x82 )')))
回答1件
あなたの回答
tips
プレビュー