Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send aiohttp post request with headers through proxy connection

What I have now (Python 3.4):

r = yield from aiohttp.request('post', URL, params=None, data=values, headers=headers)

What is in the documentation:

conn = aiohttp.ProxyConnector(proxy="http://some.proxy.com")
r = await aiohttp.get('http://python.org', connector=conn)

So, how should I send a post request with headers through proxy connection with aiohttp?

Thanks.

like image 608
v18o Avatar asked Sep 15 '25 02:09

v18o


2 Answers

connector = aiohttp.ProxyConnector(proxy="http://some.proxy.com")
session = aiohttp.ClientSession(connector=connector)
async with session.post("http://example.com/post", data=b"binary data") as resp:
    print(resp.status)

session.close()
like image 147
Andrew Svetlov Avatar answered Sep 16 '25 16:09

Andrew Svetlov


you can use this:

import aiohttp

conn = aiohttp.ProxyConnector(proxy="http://some.proxy.com")

r = await aiohttp.post('http://python.org', connector=conn, data=b"hello", headers={})

or

import aiohttp

from aiohttp import request

conn = aiohttp.ProxyConnector(proxy="http://some.proxy.com")

r = await request('post','http://python.org', connector=conn, data=b"hello", headers={})
like image 27
Pankaj Pandey Avatar answered Sep 16 '25 14:09

Pankaj Pandey