Skip to content

AttributeError: 'NoneType' object has no attribute 'close' #6

@x0day

Description

@x0day

this error is happend if proxy domain can not resolved.

import ssl
import asyncio
from python_socks.async_.asyncio import Proxy


async def test():
    proxy = Proxy.from_url('socks5://asdasdasd:1080')

    # `connect` returns standard Python socket in non-blocking mode
    # so we can pass it to asyncio.open_connection(...)
    sock = await proxy.connect(dest_host='check-host.net', dest_port=443)

    reader, writer = await asyncio.open_connection(
        host=None,
        port=None,
        sock=sock,
        ssl=ssl.create_default_context(),
        server_hostname='check-host.net',
    )

    request = (
        b'GET /ip HTTP/1.1\r\n'
        b'Host: check-host.net\r\n'
        b'Connection: close\r\n\r\n'
    )

    writer.write(request)
    response = await reader.read(-1)
    print(response)

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(test())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions