aio-libs / aioftp

ftp client/server for asyncio (http://aioftp.readthedocs.org)
Apache License 2.0
192 stars 54 forks source link

`[Errno 111] Connect call failed` with simple stat code #173

Closed nE0sIghT closed 10 months ago

nE0sIghT commented 10 months ago

Hello!

I tried to use aioftp client and getting strange error

Here is sample code:

import asyncio
import logging
import sys
from datetime import datetime, timezone
from pathlib import Path

import aioftp

async def main():
    source_path = Path("dists/bookworm/InRelease")

    async with aioftp.Client.context("mirror.yandex.ru") as ftp:  # type: ignore
        await ftp.change_directory("/debian")

        stat: dict[str, str] = await ftp.stat(source_path)

        size = int(stat["size"])  # type: ignore
        date = datetime.fromtimestamp(
            int(stat["modify"]),  # type: ignore
            tz=timezone.utc,
        )

        print(size)
        print(date)

if __name__ == "__main__":
    logging.basicConfig(
        level=logging.DEBUG,
        stream=sys.stderr,
    )

    asyncio.run(main())

With that code I getting

DEBUG:asyncio:Using selector: EpollSelector
DEBUG:aioftp.client:220-Welcome to Yandex Mirror FTP service. Your served by: mirror01sas.mds.yandex.net
DEBUG:aioftp.client:220
DEBUG:aioftp.client:USER anonymous
DEBUG:aioftp.client:331 Please specify the password.
DEBUG:aioftp.client:PASS *****
DEBUG:aioftp.client:230 Login successful.
DEBUG:aioftp.client:CWD /debian
DEBUG:aioftp.client:250 Directory successfully changed.
DEBUG:aioftp.client:MLST dists/bookworm/InRelease
DEBUG:aioftp.client:500 Unknown command.
DEBUG:aioftp.client:TYPE I
DEBUG:aioftp.client:200 Switching to Binary mode.
DEBUG:aioftp.client:EPSV
DEBUG:aioftp.client:229 Entering Extended Passive Mode (|||51574|)
DEBUG:aioftp.client:MLSD dists/bookworm
DEBUG:aioftp.client:500 Unknown command.
DEBUG:aioftp.client:TYPE I
DEBUG:aioftp.client:200 Switching to Binary mode.
DEBUG:aioftp.client:EPSV
DEBUG:aioftp.client:229 Entering Extended Passive Mode (|||55062|)
DEBUG:aioftp.client:QUIT
DEBUG:aioftp.client:221 Goodbye.
Traceback (most recent call last):
  File "/root/test.py", line 35, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/root/test.py", line 17, in main
    stat: dict[str, str] = await ftp.stat(source_path)
  File "/root/aioftp/lib/python3.10/site-packages/aioftp/client.py", line 846, in stat
    for p, info in await self.list(path.parent):
  File "/root/aioftp/lib/python3.10/site-packages/aioftp/common.py", line 128, in _to_list
    async for item in self:
  File "/root/aioftp/lib/python3.10/site-packages/aioftp/client.py", line 802, in __anext__
    cls.stream = await cls._new_stream(path)
  File "/root/aioftp/lib/python3.10/site-packages/aioftp/client.py", line 794, in _new_stream
    return await self.get_stream(command, "1xx")
  File "/root/aioftp/lib/python3.10/site-packages/aioftp/client.py", line 1181, in get_stream
    reader, writer = await self.get_passive_connection(conn_type)
  File "/root/aioftp/lib/python3.10/site-packages/aioftp/client.py", line 1160, in get_passive_connection
    reader, writer = await self._open_connection(ip, port)
  File "/usr/lib/python3.10/asyncio/streams.py", line 48, in open_connection
    transport, _ = await loop.create_connection(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1084, in create_connection
    raise OSError('Multiple exceptions: {}'.format(
OSError: Multiple exceptions: [Errno 111] Connect call failed ('213.180.204.183', 55062), [Errno 111] Connect call failed ('2a02:6b8::183', 55062, 0, 0)

Any advice about what I'm doing wrong?

Update: As per previously posted hang - I used setlocaly in wrong way

pohmelie commented 10 months ago

If you ran this code multiple times, then you see that is not the aioftp client issue, but a server issue. All I can suggest here is just retries. On 5-10 attempts I get:

DEBUG:asyncio:Using selector: EpollSelector
DEBUG:aioftp.client:220-Welcome to Yandex Mirror FTP service. Your served by: mirror01sas.mds.yandex.net
DEBUG:aioftp.client:220
DEBUG:aioftp.client:USER anonymous
DEBUG:aioftp.client:331 Please specify the password.
DEBUG:aioftp.client:PASS *****
DEBUG:aioftp.client:230 Login successful.
DEBUG:aioftp.client:CWD /debian
DEBUG:aioftp.client:250 Directory successfully changed.
DEBUG:aioftp.client:MLST dists/bookworm/InRelease
DEBUG:aioftp.client:500 Unknown command.
DEBUG:aioftp.client:TYPE I
DEBUG:aioftp.client:200 Switching to Binary mode.
DEBUG:aioftp.client:EPSV
DEBUG:aioftp.client:229 Entering Extended Passive Mode (|||55653|)
DEBUG:aioftp.client:MLSD dists/bookworm
DEBUG:aioftp.client:500 Unknown command.
DEBUG:aioftp.client:TYPE I
DEBUG:aioftp.client:200 Switching to Binary mode.
DEBUG:aioftp.client:EPSV
DEBUG:aioftp.client:229 Entering Extended Passive Mode (|||58750|)
DEBUG:aioftp.client:LIST dists/bookworm
DEBUG:aioftp.client:150 Here comes the directory listing.
DEBUG:aioftp.client:226 Directory send OK.
DEBUG:aioftp.client:QUIT
DEBUG:aioftp.client:221 Goodbye.
Traceback (most recent call last):
  File "/home/poh/pro/aioftp/yoba-ya.py", line 35, in <module>
    asyncio.run(main())
  File "/home/poh/.pyenv/versions/3.11.2/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/home/poh/.pyenv/versions/3.11.2/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/poh/.pyenv/versions/3.11.2/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/poh/pro/aioftp/yoba-ya.py", line 20, in main
    date = datetime.fromtimestamp(
           ^^^^^^^^^^^^^^^^^^^^^^^
ValueError: year 643056 is out of range
nE0sIghT commented 10 months ago

Thanks for quick reply!
I agree that it looks like server issue so it need to be further tested.