竹不睡 2023-09-26 19:34 采纳率: 0%
浏览 329

Huggingface遇到OSError: We couldn‘t connect to ‘https://huggingface.co‘ to load this file

在pycharm运行后出现这个问题网上找到办法不是看不懂,就是没什么有,求带带,给个解答。

Building prefix dict from the default dictionary ...
Loading model from cache C:\Users\86138\AppData\Local\Temp\jieba.cache
Loading model cost 0.537 seconds.
Prefix dict has been built successfully.
'(MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-chinese/resolve/main/config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x0000016B4C2BCF90>, 'Connection to huggingface.co timed out. (connect timeout=10)'))"), '(Request ID: fbeab398-47b3-4c26-bd41-c3a2810e733f)')' thrown while requesting HEAD https://huggingface.co/bert-base-chinese/resolve/main/config.json
'(MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-chinese/resolve/main/config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x0000016B4C2BFF10>, 'Connection to huggingface.co timed out. (connect timeout=10)'))"), '(Request ID: 62b1ea0a-3756-4a14-a626-7486013a2ab7)')' thrown while requesting HEAD https://huggingface.co/bert-base-chinese/resolve/main/config.json
Traceback (most recent call last):
  File "C:\Python311\Lib\site-packages\urllib3\connection.py", line 203, in _new_conn
    sock = connection.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
    raise err
  File "C:\Python311\Lib\site-packages\urllib3\util\connection.py", line 73, in create_connection
    sock.connect(sa)
TimeoutError: timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Python311\Lib\site-packages\urllib3\connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\urllib3\connectionpool.py", line 491, in _make_request
    raise new_e
  File "C:\Python311\Lib\site-packages\urllib3\connectionpool.py", line 467, in _make_request
    self._validate_conn(conn)
  File "C:\Python311\Lib\site-packages\urllib3\connectionpool.py", line 1092, in _validate_conn
    conn.connect()
  File "C:\Python311\Lib\site-packages\urllib3\connection.py", line 611, in connect
    self.sock = sock = self._new_conn()
                       ^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\urllib3\connection.py", line 212, in _new_conn
    raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x0000016B4C2BFF10>, 'Connection to huggingface.co timed out. (connect timeout=10)')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Python311\Lib\site-packages\requests\adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\urllib3\connectionpool.py", line 844, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\urllib3\util\retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-chinese/resolve/main/config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x0000016B4C2BFF10>, 'Connection to huggingface.co timed out. (connect timeout=10)'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python311\Lib\site-packages\huggingface_hub\file_download.py", line 1230, in hf_hub_download
    metadata = get_hf_file_metadata(
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\huggingface_hub\utils\_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\huggingface_hub\file_download.py", line 1597, in get_hf_file_metadata
    r = _request_wrapper(
        ^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\huggingface_hub\file_download.py", line 417, in _request_wrapper
    response = _request_wrapper(
               ^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\huggingface_hub\file_download.py", line 452, in _request_wrapper
    return http_backoff(
           ^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\huggingface_hub\utils\_http.py", line 274, in http_backoff
    raise err
  File "C:\Python311\Lib\site-packages\huggingface_hub\utils\_http.py", line 258, in http_backoff
    response = session.request(method=method, url=url, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\requests\sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\huggingface_hub\utils\_http.py", line 63, in send
    return super().send(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\requests\adapters.py", line 507, in send
    raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-chinese/resolve/main/config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x0000016B4C2BFF10>, 'Connection to huggingface.co timed out. (connect timeout=10)'))"), '(Request ID: 62b1ea0a-3756-4a14-a626-7486013a2ab7)')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Python311\Lib\site-packages\transformers\utils\hub.py", line 429, in cached_file
    resolved_file = hf_hub_download(
                    ^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\huggingface_hub\utils\_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\huggingface_hub\file_download.py", line 1347, in hf_hub_download
    raise LocalEntryNotFoundError(
huggingface_hub.utils._errors.LocalEntryNotFoundError: An error happened while trying to locate the file on the Hub and we cannot find the requested files in the local cache. Please check your connection and try again or make sure your Internet connection is on.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Python311\Lib\site-packages\transformers\configuration_utils.py", line 675, in _get_config_dict
    resolved_config_file = cached_file(
                           ^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\transformers\utils\hub.py", line 469, in cached_file
    raise EnvironmentError(
OSError: We couldn't connect to 'https://huggingface.co' to load this file, couldn't find it in the cached files and it looks like bert-base-chinese is not the path to a directory containing a file named config.json.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
python-BaseException

  • 写回答

1条回答 默认 最新

  • 专家-赤兔[在线] 优质创作者: 编程框架技术领域 2023-09-27 09:22
    关注

    该回复引自免费微信小程序-皆我百晓生:


    根据错误提示,出现了连接超时的错误,可能是由于网络连接不稳定或者防火墙等原因导致无法连接到Huggingface网站。下面提供几种解决方案:

    1. 检查网络连接:确保你的网络连接正常,并且没有被防火墙等安全软件阻止。

    2. 使用代理:如果你使用的网络环境需要代理服务器,请确保你已正确配置代理,并且可以访问Huggingface网站。

    3. 使用离线模式:在运行代码之前,可以尝试将Huggingface库设置为离线模式。具体方法请查看Huggingface官方文档中的"Offline Mode"部分,以了解如何在离线环境中使用Huggingface库。

    4. 使用其他镜像源:Huggingface库有一些镜像源可以使用,例如清华大学提供的镜像源。你可以尝试将Huggingface库的默认镜像源更改为其他可用的镜像源。在PyTorch中,可以通过设置环境变量TORCH_HOME来更改默认的Huggingface镜像源。

    这些解决方案中的任何一种都可能解决你的问题,具体选择取决于你的网络环境和需求。希望可以帮助到你!

    评论

报告相同问题?

问题事件

  • 创建了问题 9月26日