bluet / proxybroker2

The New (auto rotate) Proxy [Finder | Checker | Server]. HTTP(S) & SOCKS :performing_arts:
Apache License 2.0
716 stars 112 forks source link

OSError: [WinError 10038] An operation was attempted on something that is not a socket #59

Closed boxxello closed 2 years ago

boxxello commented 2 years ago

Hello, I'm having issues with the library, this is the stacktrace it threw:

1.09.74.59:476: Error at creating: 
Traceback (most recent call last):
  File "C:/Users/boxxo/PycharmProjects/proxy_scraper/proxyScraper.py", line 238, in <module>
    loop.run_until_complete(tasks)
  File "C:\ProgramData\Anaconda3\envs\proxy_scraper\lib\asyncio\base_events.py", line 475, in run_until_complete
    self.run_forever()
  File "C:\ProgramData\Anaconda3\envs\proxy_scraper\lib\asyncio\base_events.py", line 442, in run_forever
    self._run_once()
  File "C:\ProgramData\Anaconda3\envs\proxy_scraper\lib\asyncio\base_events.py", line 1426, in _run_once
    event_list = self._selector.select(timeout)
  File "C:\ProgramData\Anaconda3\envs\proxy_scraper\lib\selectors.py", line 323, in select
    r, w, _ = self._select(self._readers, self._writers, [], timeout)
  File "C:\ProgramData\Anaconda3\envs\proxy_scraper\lib\selectors.py", line 314, in _select
    r, w, x = select.select(r, w, w, timeout)
OSError: [WinError 10038] An operation was attempted on something that is not a socket

Process finished with exit code 1

and these are the functions, even shown in the examples I ran:

def run_broker(limit_amnt):
    """
        Run the broker lib functions to find proxies and call the save function asyncronously
    """
    try:
        proxies = asyncio.Queue()
        broker = Broker(proxies)
        tasks = asyncio.gather(broker.find(types=['HTTP', 'HTTPS'], limit=limit_amnt),
                                save(proxies, filename=pathTextFile))
        #tasks = asyncio.gather(
        #   broker.find(types=['HTTP', 'HTTPS'], limit=100),
        #   show(proxies))
        loop = asyncio.get_event_loop()
        loop.run_until_complete(tasks)
    except:
        logging.error(traceback.format_exc())

async def save(proxies, filename):
    """Save proxies to a file."""
    with open(filename, 'w') as f:
        while True:
            proxy = await proxies.get()
            if proxy is None:
                break
            proto = 'https' if 'HTTPS' in proxy.types else 'http'
            row = '%s://%s:%d\n' % (proto, proxy.host, proxy.port)
            f.write(row)

Could anyone help me with it?

bluet commented 2 years ago

@boxxello We've done some changes, can you try the latest version?

boxxello commented 2 years ago

@bluet I'm sorry. I actually don't have that project anymore and I can't reproduce a minimal snippet cause it's been some time since I worked on that project.

bluet commented 2 years ago

@boxxello no worries. Thanks for this bug report, still. :+1:

stefanDeveloper commented 1 year ago

I actually run into the same issue somehow

ziloka commented 1 year ago

please make a minimal reproducible example

stefanDeveloper commented 1 year ago

The following code results in this error:

import asyncio
from proxybroker import Broker

async def show(proxies):
    while True:
        proxy = await proxies.get()
        if proxy is None: break
        print('Found proxy: %s' % proxy)

proxies = asyncio.Queue()
broker = Broker(proxies)
tasks = asyncio.gather(
    broker.find(types=['HTTP', 'HTTPS'], countries=["SG"], limit=10),
    show(proxies))

loop = asyncio.get_event_loop()
loop.run_until_complete(tasks)

Any idea why?

br-olf commented 1 year ago

found the issue in resolver.py line 51:

    @staticmethod
    def host_is_ip(host):
        """Check a host is IP address."""
        # TODO: add IPv6 support
        try:
            ipaddress.IPv4Address(host)
        except ipaddress.AddressValueError:
            return False
        else:
            return True
>>> import ipaddress
>>> ipaddress.IPv4Address("1.09.74.59")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/ipaddress.py", line 1305, in __init__
    self._ip = self._ip_int_from_string(addr_str)
  File "/usr/local/lib/python3.10/ipaddress.py", line 1197, in _ip_int_from_string
    raise AddressValueError("%s in %r" % (exc, ip_str)) from None
ipaddress.AddressValueError: Leading zeros are not permitted in '09' in '1.09.74.59'
>>> ipaddress.IPv4Address("1.9.74.59")
IPv4Address('1.9.74.59')

A ipaddress.AddressValueError is also returned if the IP contains leading zeros.

stefanDeveloper commented 1 year ago

As described by @br-olf , the issue is resolved by removing the leading zeros in an IP address. See #123