V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
proxytoworld
V2EX  ›  问与答

使用 Python 的 requests 包请求如何禁止 Python 进行 url 规范化

  •  
  •   proxytoworld · Sep 20, 2023 · 873 views
    This topic created in 953 days ago, the information mentioned may be changed or developed.

    我有 domain

    • https://domain
    • http://domain

    uri: /prefix/%2E%2E/postfix

    当使用 request.get(domain + uri)请求时,会有如下情况

    • 如果 HTTP Schema 是 https 则实际请求 https://domain/prefix/%2E%2E/postfix 或者 https://domain/prefix/../postfix

    • 如果 HTTP Schema 是 https 则实际请求 http://domain/postfix

    问了 claude ,说是 HTTP 会使用 urllib3 进行 url 规范化,将 url 解码,如果是..则进行合并。 如果是 HTTPS 则会给 TLS ,而不会进行规范化

    现在我不想让 python 合并 url ,希望 HTTP 和 HTTPS 表现一样(不会合并)该怎么办呢,能使用 request 实现吗,我知道可以使用原生的库http.client.HTTPConnection('www.python.org')实现,但这种太底层了,套代理好麻烦

    有办法实现吗

    1 replies    2023-09-20 11:27:40 +08:00
    someday3
        1
    someday3  
       Sep 20, 2023
    那两个列表理都是 https ,第二个是写错了吧,应该是 http 吧

    我不知道跟 python 版本有没有关系,我是用 python3.8 ,本地测试,wireshark 抓的包,没看到你说的问题。在 url 部分都是传入的路径,二进制编码都是..
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5097 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 09:09 · PVG 17:09 · LAX 02:09 · JFK 05:09
    ♥ Do have faith in what you're doing.