код прилагается:
Код: Выделить всё
---------------------------------------------------------------------------
JsException Traceback (most recent call last)
File /lib/python3.12/site-packages/urllib3/contrib/emscripten/fetch.py:385, in send_request(request)
383 js_xhr.setRequestHeader(name, value)
--> 385 js_xhr.send(to_js(request.body))
387 headers = dict(Parser().parsestr(js_xhr.getAllResponseHeaders()))
JsException: NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://facultyprofiles.hkust-gz.edu.cn/'.
During handling of the above exception, another exception occurred:
_RequestError Traceback (most recent call last)
File /lib/python3.12/site-packages/urllib3/contrib/emscripten/connection.py:118, in EmscriptenHTTPConnection.request(self, method, url, body, headers, chunked, preload_content, decode_content, enforce_content_length)
117 if self._response is None:
--> 118 self._response = send_request(request)
119 except _TimeoutError as e:
File /lib/python3.12/site-packages/urllib3/contrib/emscripten/fetch.py:400, in send_request(request)
399 elif err.name == "NetworkError":
--> 400 raise _RequestError(err.message, request=request)
401 else:
402 # general http error
_RequestError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://facultyprofiles.hkust-gz.edu.cn/'.
The above exception was the direct cause of the following exception:
HTTPException Traceback (most recent call last)
File /lib/python3.12/site-packages/urllib3/connectionpool.py:793, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
792 # Make the request on the HTTPConnection object
--> 793 response = self._make_request(
794 conn,
795 method,
796 url,
797 timeout=timeout_obj,
798 body=body,
799 headers=headers,
800 chunked=chunked,
801 retries=retries,
802 response_conn=response_conn,
803 preload_content=preload_content,
804 decode_content=decode_content,
805 **response_kw,
806 )
808 # Everything went great!
File /lib/python3.12/site-packages/urllib3/connectionpool.py:496, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
495 try:
--> 496 conn.request(
497 method,
498 url,
499 body=body,
500 headers=headers,
501 chunked=chunked,
502 preload_content=preload_content,
503 decode_content=decode_content,
504 enforce_content_length=enforce_content_length,
505 )
507 # We are swallowing BrokenPipeError (errno.EPIPE) since the server is
508 # legitimately able to close the connection after sending a valid response.
509 # With this behaviour, the received response is still readable.
File /lib/python3.12/site-packages/urllib3/contrib/emscripten/connection.py:122, in EmscriptenHTTPConnection.request(self, method, url, body, headers, chunked, preload_content, decode_content, enforce_content_length)
121 except _RequestError as e:
--> 122 raise HTTPException(e.message) from e
HTTPException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://facultyprofiles.hkust-gz.edu.cn/'.
During handling of the above exception, another exception occurred:
ProtocolError Traceback (most recent call last)
File /lib/python3.12/site-packages/requests/adapters.py:486, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
485 try:
--> 486 resp = conn.urlopen(
487 method=request.method,
488 url=url,
489 body=request.body,
490 headers=request.headers,
491 redirect=False,
492 assert_same_host=False,
493 preload_content=False,
494 decode_content=False,
495 retries=self.max_retries,
496 timeout=timeout,
497 chunked=chunked,
498 )
500 except (ProtocolError, OSError) as err:
File /lib/python3.12/site-packages/urllib3/connectionpool.py:847, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
845 new_e = ProtocolError("Connection aborted.", new_e)
--> 847 retries = retries.increment(
848 method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
849 )
850 retries.sleep()
File /lib/python3.12/site-packages/urllib3/util/retry.py:470, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)
469 if read is False or method is None or not self._is_method_retryable(method):
--> 470 raise reraise(type(error), error, _stacktrace)
471 elif read is not None:
File /lib/python3.12/site-packages/urllib3/util/util.py:38, in reraise(tp, value, tb)
37 if value.__traceback__ is not tb:
---> 38 raise value.with_traceback(tb)
39 raise value
File /lib/python3.12/site-packages/urllib3/connectionpool.py:793, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
792 # Make the request on the HTTPConnection object
--> 793 response = self._make_request(
794 conn,
795 method,
796 url,
797 timeout=timeout_obj,
798 body=body,
799 headers=headers,
800 chunked=chunked,
801 retries=retries,
802 response_conn=response_conn,
803 preload_content=preload_content,
804 decode_content=decode_content,
805 **response_kw,
806 )
808 # Everything went great!
File /lib/python3.12/site-packages/urllib3/connectionpool.py:496, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
495 try:
--> 496 conn.request(
497 method,
498 url,
499 body=body,
500 headers=headers,
501 chunked=chunked,
502 preload_content=preload_content,
503 decode_content=decode_content,
504 enforce_content_length=enforce_content_length,
505 )
507 # We are swallowing BrokenPipeError (errno.EPIPE) since the server is
508 # legitimately able to close the connection after sending a valid response.
509 # With this behaviour, the received response is still readable.
File /lib/python3.12/site-packages/urllib3/contrib/emscripten/connection.py:122, in EmscriptenHTTPConnection.request(self, method, url, body, headers, chunked, preload_content, decode_content, enforce_content_length)
121 except _RequestError as e:
--> 122 raise HTTPException(e.message) from e
ProtocolError: ('Connection aborted.', HTTPException("Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://facultyprofiles.hkust-gz.edu.cn/'."))
During handling of the above exception, another exception occurred:
ConnectionError Traceback (most recent call last)
Cell In[1], line 5
1 import requests
3 url = "https://facultyprofiles.hkust-gz.edu.cn/"
----> 5 response = requests.get(url)
7 if response.status_code == 200:
8 with open("infhfaculty.html", "w", encoding='utf-8') as file:
File /lib/python3.12/site-packages/requests/api.py:73, in get(url, params, **kwargs)
62 def get(url, params=None, **kwargs):
63 r"""Sends a GET request.
64
65 :param url: URL for the new :class:`Request` object.
(...)
70 :rtype: requests.Response
71 """
---> 73 return request("get", url, params=params, **kwargs)
File /lib/python3.12/site-packages/requests/api.py:59, in request(method, url, **kwargs)
55 # By using the 'with' statement we are sure the session is closed, thus we
56 # avoid leaving sockets open which can trigger a ResourceWarning in some
57 # cases, and look like a memory leak in others.
58 with sessions.Session() as session:
---> 59 return session.request(method=method, url=url, **kwargs)
File /lib/python3.12/site-packages/requests/sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
584 send_kwargs = {
585 "timeout": timeout,
586 "allow_redirects": allow_redirects,
587 }
588 send_kwargs.update(settings)
--> 589 resp = self.send(prep, **send_kwargs)
591 return resp
File /lib/python3.12/site-packages/requests/sessions.py:703, in Session.send(self, request, **kwargs)
700 start = preferred_clock()
702 # Send the request
--> 703 r = adapter.send(request, **kwargs)
705 # Total elapsed time of the request (approximately)
706 elapsed = preferred_clock() - start
File /lib/python3.12/site-packages/requests/adapters.py:501, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
486 resp = conn.urlopen(
487 method=request.method,
488 url=url,
(...)
497 chunked=chunked,
498 )
500 except (ProtocolError, OSError) as err:
--> 501 raise ConnectionError(err, request=request)
503 except MaxRetryError as e:
504 if isinstance(e.reason, ConnectTimeoutError):
505 # TODO: Remove this in 3.0.0: see #2811
ConnectionError: ('Connection aborted.', HTTPException("Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://facultyprofiles.hkust-gz.edu.cn/'."))
Подробнее здесь: https://stackoverflow.com/questions/789 ... on-jupyter