我使用aiohttp客户端向URL发送请求并收集重定向URL。
在我的示例中,重定向URL中包含Unicode文本。我想要未经修改的。
例如,实际的重定向网址是example.com/förderprojekte-e-v,,但是aiohttp客户端自动编码它&返回me example.com/f\udcf6rderprojekte-e-v.
如何使aiohttp禁用重定向urls的自动编码。
对于请求模块,this解决方案可以工作,但是我需要aiohttp的帮助。
我的代码:
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或者至少告诉我如何将\udcf6 6转换为
发布于 2021-08-12 02:21:21
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)请参阅https://docs.aiohttp.org/en/stable/web_reference.html中的请求对象属性
https://stackoverflow.com/questions/68698478
复制相似问题