romis2012 / aiosocksy Goto Github PK
View Code? Open in Web Editor NEWSOCKS proxy client for aiohttp 3.x
License: Apache License 2.0
SOCKS proxy client for aiohttp 3.x
License: Apache License 2.0
import asyncio
import aiohttp
from aiosocksy import Socks5Auth
from aiosocksy.connector import ProxyConnector, ProxyClientRequest
async def fetch(url):
connector = ProxyConnector()
socks = 'socks4://127.0.0.1:8080'
async with aiohttp.ClientSession(connector=connector, request_class=ProxyClientRequest) as session:
async with session.get(url, proxy=socks) as response:
print(await response.text())
loop = asyncio.get_event_loop()
loop.run_until_complete(fetch('http://ie.com/'))
generates:
Original exception was:
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
return future.result()
File "", line 5, in fetch
File "/home/debian/.local/lib/python3.6/site-packages/aiohttp/client.py", line 783, in aenter
self._resp = await self._coro
File "/home/debian/.local/lib/python3.6/site-packages/aiohttp/client.py", line 320, in _request
traces=traces
File "/home/debian/.local/lib/python3.6/site-packages/aiohttp/connector.py", line 418, in connect
traces=traces
File "/home/debian/.local/lib/python3.6/site-packages/aiohttp/connector.py", line 728, in _create_connection
traces=traces
File "/home/debian/.local/lib/python3.6/site-packages/aiosocksy/connector.py", line 56, in _create_proxy_connection
return await self._create_socks_connection(req, traces=traces)
File "/home/debian/.local/lib/python3.6/site-packages/aiosocksy/connector.py", line 108, in _create_socks_connection
server_hostname=req.host if sslcontext else None)
File "/home/debian/.local/lib/python3.6/site-packages/aiosocksy/connector.py", line 60, in _wrap_create_socks_connection
return await create_connection(*args, **kwargs)
File "/home/debian/.local/lib/python3.6/site-packages/aiosocksy/init.py", line 81, in create_connection
await waiter
aiosocksy.errors.SocksError: Can not connect to ie.com:80. [Errno 0x5b]: Request rejected or failed
socks5 works
When use aiosocksy for simple 'socks5://' proxy with aiohttp 3.3.0 I get the following error:
TypeError: _create_proxy_connection() takes from 2 to 3 positional arguments but 4 were given
Is it possible to fix this?
How i can close connection to socks4 proxy (local tor instance)? After writer.close() connection to remote target closed, but pair connection to local port of tor is established and stay in this state till restart application.
await waiter
aiosocksy.errors.SocksError: Can not connect to api.ipify.org:443. [Errno 0x5b]: Request rejected or failed
What to do?
Python 3.7 added TLS support in Asyncio. It would be cool if a SOCKS connection could also be upgraded with StartTLS. See https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop.start_tls
In connector.py, you make the import
from aiohttp.client_exceptions import (
ServerFingerprintMismatch,
certificate_errors,
ssl_errors
but certificate_errors
no longer exists from version 3.4 of aiohttp:
https://github.com/aio-libs/aiohttp/blob/3.3/aiohttp/client_exceptions.py
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.