aiohttp icon indicating copy to clipboard operation
aiohttp copied to clipboard

when I use the proxy option for client get method, I got 'Constructor parameter must be string'

Open xgnit opened this issue 8 years ago • 4 comments

Code ist simple

async def run(self, proxy):
    proxy_for_requests = {'https': proxy}
    try:
        async with aiohttp.ClientSession() as session:
            async with session.get(url='https://www.google.com', proxy=proxy_for_requests,
                                                timeout=5, headers=self.get_headers()) as resp:
                return proxy
    except Exception as e:
        print(str(e))
        return None

Expected: When it's a timeout problem, it returns None.

Actual: this function always raises the error: "Constructor parameter should be str". I removed the option timeout and headers, but it still the same case. Only when I left the only option url, it can run correctly. It seems the options for this session.get are not available.

my aiohttp is 3.4.4 and my OS is windows 10.

xgnit avatar Nov 25 '18 19:11 xgnit

GitMate.io thinks the contributor most likely able to help you is @asvetlov.

Possibly related issues are https://github.com/aio-libs/aiohttp/issues/1455 (How to use Proxy?), https://github.com/aio-libs/aiohttp/issues/1167 (Client session method that accepts http verb as a parameter), https://github.com/aio-libs/aiohttp/issues/1293 (Use timeout in client), https://github.com/aio-libs/aiohttp/issues/3385 (Disable body parameter in HTTPException constructor), and https://github.com/aio-libs/aiohttp/issues/499 (Url GET parameters are lost when redirecting).

aio-libs-bot avatar Nov 25 '18 19:11 aio-libs-bot

I found the error, I passed an argument format as the python requests, so basically I passed a dictionary object. When I changed it to string, everything worked fine. But it seems it does not work work with https. I hope you guys can make a update for this.

xgnit avatar Nov 25 '18 19:11 xgnit

So maybe raise an error to say that the proxy argument format is not correct rather than let the yarl URL do the job?

xgnit avatar Nov 25 '18 19:11 xgnit

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

If you feel like there's important points made in this discussion, please include those exceprts into that new issue.

lock[bot] avatar Nov 25 '19 20:11 lock[bot]