Skip to content

Instantly share code, notes, and snippets.

@meejah meejah/aio_client.py
Created Mar 23, 2018

Embed
What would you like to do?
import asyncio
import aiohttp
from aiosocks.connector import ProxyConnector, ProxyClientRequest
async def fetch(session, socks_port, url):
conn = ProxyConnector(remote_resolve=True)
async with aiohttp.ClientSession(connector=conn, request_class=ProxyClientRequest) as session:
request = session.get(
url,
proxy='socks5://127.0.0.1:{}'.format(socks_port),
headers={
"Host": "timaq4ygg2iegci7.onion"
}
)
print(dir(request))
async with request as resp:
print("Return status: {}".format(resp.status))
print(dir(resp))
print(resp.raw_headers)
if resp.status == 200:
data = await resp.text()
return data
return None
async def do_client_stuff():
async with aiohttp.ClientSession() as session:
html = await fetch(session, 9050, 'http://timaq4ygg2iegci7.onion')
# html = await fetch(session, 9050, 'https://www.torproject.org')
print("got data:\n{}".format(html))
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(
do_client_stuff()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.