首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python客户端-禁用编码重定向url

Python客户端-禁用编码重定向url
EN

Stack Overflow用户
提问于 2021-08-08 07:02:03
回答 1查看 246关注 0票数 1

我使用aiohttp客户端向URL发送请求并收集重定向URL。

在我的示例中,重定向URL中包含Unicode文本。我想要未经修改的。

例如,实际的重定向网址是example.com/förderprojekte-e-v,,但是aiohttp客户端自动编码它&返回me example.com/f\udcf6rderprojekte-e-v.

如何使aiohttp禁用重定向urls的自动编码。

对于请求模块,this解决方案可以工作,但是我需要aiohttp的帮助。

我的代码:

代码语言:javascript
复制
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转换为

EN

回答 1

Stack Overflow用户

发布于 2021-08-12 02:21:21

代码语言:javascript
复制
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中的请求对象属性

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68698478

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档