添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

ConnectionResetError: [Errno 54] Connection reset by peer #8483

@betterMax

Description

System Info

I use this code:

search = GoogleSearchAPIWrapper()
tool = Tool(
    name="Google Search",
    description="Search Google for recent results.",
    func=search.run,
tool.run("Obama's first name?")

The result looks fine. But when I use the code below

search = GoogleSearchAPIWrapper()
tools = [
    Tool(
        name="google-search",
        func=search.run,
        description="useful when you need to search google to answer questions about current events"
agent = initialize_agent(
    tools,
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True,
    max_iterations=6)
response = agent("What is the latest news about the Mars rover?")
print(response)

I get this error:

File /opt/homebrew/anaconda3/envs/common_3.8/lib/python3.8/site-packages/googleapiclient/http.py:191, in _retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args, **kwargs)
    189 try:
    190     exception = None
--> 191     resp, content = http.request(uri, method, *args, **kwargs)
    192 # Retry on SSL errors and socket timeout errors.
    193 except _ssl_SSLError as ssl_error:
File /opt/homebrew/anaconda3/envs/common_3.8/lib/python3.8/site-packages/httplib2/__init__.py:1724, in Http.request(self, uri, method, body, headers, redirections, connection_type)
   1722             content = b""
   1723         else:
-> 1724             (response, content) = self._request(
   1725                 conn, authority, uri, request_uri, method, body, headers, redirections, cachekey,
   1726             )
   1727 except Exception as e:
   1728     is_timeout = isinstance(e, socket.timeout)
File /opt/homebrew/anaconda3/envs/common_3.8/lib/python3.8/site-packages/httplib2/__init__.py:1444, in Http._request(self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey)
   1441 if auth:
   1442     auth.request(method, request_uri, headers, body)
-> 1444 (response, content) = self._conn_request(conn, request_uri, method, body, headers)
   1446 if auth:
   1447     if auth.response(response, body):
File /opt/homebrew/anaconda3/envs/common_3.8/lib/python3.8/site-packages/httplib2/__init__.py:1396, in Http._conn_request(self, conn, request_uri, method, body, headers)
   1394     pass
   1395 try:
-> 1396     response = conn.getresponse()
   1397 except (http.client.BadStatusLine, http.client.ResponseNotReady):
   1398     # If we get a BadStatusLine on the first try then that means
   1399     # the connection just went stale, so retry regardless of the
   1400     # number of RETRIES set.
   1401     if not seen_bad_status_line and i == 1:
File /opt/homebrew/anaconda3/envs/common_3.8/lib/python3.8/http/client.py:1348, in HTTPConnection.getresponse(self)
   1346 try:
   1347     try:
-> 1348         response.begin()
   1349     except ConnectionError:
   1350         self.close()
File /opt/homebrew/anaconda3/envs/common_3.8/lib/python3.8/http/client.py:316, in HTTPResponse.begin(self)
    314 # read until we get a non-100 response
    315 while True:
--> 316     version, status, reason = self._read_status()
    317     if status != CONTINUE:
    318         break
File /opt/homebrew/anaconda3/envs/common_3.8/lib/python3.8/http/client.py:277, in HTTPResponse._read_status(self)
    276 def _read_status(self):
--> 277     line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    278     if len(line) > _MAXLINE:
    279         raise LineTooLong("status line")
File /opt/homebrew/anaconda3/envs/common_3.8/lib/python3.8/socket.py:669, in SocketIO.readinto(self, b)
    667 while True:
    668     try:
--> 669         return self._sock.recv_into(b)
    670     except timeout:
    671         self._timeout_occurred = True
File /opt/homebrew/anaconda3/envs/common_3.8/lib/python3.8/ssl.py:1241, in SSLSocket.recv_into(self, buffer, nbytes, flags)
   1237     if flags != 0:
   1238         raise ValueError(
   1239           "non-zero flags not allowed in calls to recv_into() on %s" %
   1240           self.__class__)
-> 1241     return self.read(nbytes, buffer)
   1242 else:
   1243     return super().recv_into(buffer, nbytes, flags)
File /opt/homebrew/anaconda3/envs/common_3.8/lib/python3.8/ssl.py:1099, in SSLSocket.read(self, len, buffer)
   1097 try:
   1098     if buffer is not None:
-> 1099         return self._sslobj.read(len, buffer)
   1100     else:
   1101         return self._sslobj.read(len)
ConnectionResetError: [Errno 54] Connection reset by peer

Who can help?

No response

Information

  • The official example notebooks/scripts
  • My own modified scripts
  • Related Components

  • LLMs/Chat Models
  • Embedding Models
  • Prompts / Prompt Templates / Prompt Selectors
  • Output Parsers
  • Document Loaders
  • Vector Stores / Retrievers
  • Memory
  • Agents / Agent Executors
  • Tools / Toolkits
  • Chains
  • Callbacks/Tracing
  • Async
  • Reproduction

    search = GoogleSearchAPIWrapper()
    tools = [
        Tool(
            name="google-search",
            func=search.run,
            description="useful when you need to search google to answer questions about current events"
    agent = initialize_agent(
        tools,
        agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
        verbose=True,
        max_iterations=6)
    response = agent("What is the latest news about the Mars rover?")
    print(response)
    

    Expected behavior

    Hope to know the reason and how to prevent the issue.