1

I'm using aiohttp client to send request to an URL and collecting the redirected URLs.

In my case, the redirected URL contains Unicode text in it. I want it unmodified.

For eg the actual redirected URL is example.com/förderprojekte-e-v, but aiohttp client auto encodes it & returns me example.com/f\udcf6rderprojekte-e-v.

How to make aiohttp to disable auto encoding of redirected urls.

For requests module, this solution works, but I need help for aiohttp.

My code:

async fetch(url):
    #url = 'https://www.example.com/test/123'
    async with client.get(url, allow_redirects = True ) as resp:
        html = await resp.read()
        redir_url = str(resp.url)
        #example.com/f\udcf6rderprojekte-e-v

or atleast tell me how to convert \udcf6 to ö

RG_RG
  • 349
  • 5
  • 8

1 Answers1

0
async def handle_redirected_url(request):
    # https://
    scheme = request.scheme
    # example.com
    host = request.host
    # /f\udcf6rderprojekte-e-v
    unencoded_path = request.raw_path
    
    unencoded_url = scheme+host+unencoded_path
    return web.json_response(status=200, data={'unencoded_url': unencoded_url)

See request object attributes in https://docs.aiohttp.org/en/stable/web_reference.html

Deik
  • 134
  • 9
  • I updated my code in the question. can you explain how your answer works? my question is about aiohttp client, your answer seems like aiohttp server. – RG_RG Aug 13 '21 at 09:19