m9_22458869 2024-08-01 16:37 采纳率: 0%
浏览 5

(标签-HTTP|关键词-Proxy)

源代码

from langchain.tools import YouTubeSearchTool,Tool
proxies = {'HTTP': 'HTTP://127.0.0.1:7890', 'HTTPS': 'HTTP://127.0.0.1:7890'}
tool = YouTubeSearchTool(proxies ='http://localhost:7890')
tool.run("langchain")

出现错误:
requests.exceptions.ProxyError: HTTPSConnectionPool(host='youtube.com', port=443): Max retries exceeded with url: /results?search_query=langchain (Caused by ProxyError('Unable to connect to proxy', SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1135)'))))

同样的proxies参数下可以连接到hugging face

ping不通youtube.com
但是在网页上打得开

错误详情:

urllib3.exceptions.SSLError: TLS/SSL connection has been closed (EOF) (_ssl.c:1135)

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

urllib3.exceptions.ProxyError: ('Unable to connect to proxy', SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1135)')))

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

Traceback (most recent call last):
  File "C:\Users\1\.conda\envs\prompt02\lib\site-packages\requests\adapters.py", line 670, in send
    resp = conn.urlopen(
  File "C:\Users\1\.conda\envs\prompt02\lib\site-packages\urllib3\connectionpool.py", line 843, in urlopen
    retries = retries.increment(
  File "C:\Users\1\.conda\envs\prompt02\lib\site-packages\urllib3\util\retry.py", line 519, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='youtube.com', port=443): Max retries exceeded with url: /results?search_query=langchain (Caused by ProxyError('Unable to connect to proxy', SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1135)'))))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/1/Desktop/Project/learnprompt/agent_llm.py", line 66, in <module>
    tool.run("langchain")
  File "C:\Users\1\.conda\envs\prompt02\lib\site-packages\langchain_core\tools.py", line 635, in run
    raise error_to_raise
  File "C:\Users\1\.conda\envs\prompt02\lib\site-packages\langchain_core\tools.py", line 608, in run
    response = context.run(self._run, *tool_args, **tool_kwargs)
  File "C:\Users\1\.conda\envs\prompt02\lib\site-packages\langchain_community\tools\youtube\search.py", line 55, in _run
    return self._search(person, num_results)
  File "C:\Users\1\.conda\envs\prompt02\lib\site-packages\langchain_community\tools\youtube\search.py", line 35, in _search
    results = YoutubeSearch(person, num_results).to_json()
  File "C:\Users\1\.conda\envs\prompt02\lib\site-packages\youtube_search\__init__.py", line 10, in __init__
    self.videos = self._search()
  File "C:\Users\1\.conda\envs\prompt02\lib\site-packages\youtube_search\__init__.py", line 16, in _search
    response = requests.get(url).text
  File "C:\Users\1\.conda\envs\prompt02\lib\site-packages\requests\api.py", line 75, in get
    return request("get", url, params=params, **kwargs)
  File "C:\Users\1\.conda\envs\prompt02\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\1\.conda\envs\prompt02\lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\1\.conda\envs\prompt02\lib\site-packages\requests\sessions.py", line 704, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\1\.conda\envs\prompt02\lib\site-packages\requests\adapters.py", line 699, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='youtube.com', port=443): Max retries exceeded with url: /results?search_query=langchain (Caused by ProxyError('Unable to connect to proxy', SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1135)'))))
  • 写回答

1条回答 默认 最新

  • 码农阿豪@新空间 新星创作者: 前端开发技术领域 2024-08-06 10:51
    关注
    让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言
    根据错误提示,请求无法连接代理,引起这个问题大概率是代理设置或者代理配置的问题。可以尝试以下几种解决方法:
    1. 检查代理配置是否正确:确保代理服务器的地址和端口号正确,并且代理服务器是可用的。

    2. 使用不同的代理方式:尝试使用其他代理方式,比如socks代理或者其他http代理,看是否能够解决问题。

    3. 确保网络连接正常:检查网络连接是否正常,可以尝试ping其他网站或者使用浏览器打开其他网站确认网络连接是否通畅。

    4. 可能是对方网站反爬机制导致:有一些网站会检测到代理IP,从而导致无法访问。可以尝试更换代理IP或者使用更高匿名性的代理IP。 案例:

    import requests
    proxies = {
        'http': 'http://127.0.0.1:7890',
        'https': 'http://127.0.0.1:7890'
    }
    url = "https://www.baidu.com/"
    try:
        response = requests.get(url, proxies=proxies)
        print(response.text)
    except requests.exceptions.ProxyError as e:
        print("ProxyError:", e)
    except requests.exceptions.SSLError as e:
        print("SSLError:", e)
    except requests.exceptions.ConnectionError as e:
        print("ConnectionError:", e)
    

    通过以上方法可以尝试解决请求无法连接代理的问题。希望对您有所帮助。

    评论

报告相同问题?

问题事件

  • 创建了问题 8月1日