当我在 python 中发送 http2 请求时收到重复的伪标头字段 b':path' 错误

问题描述 投票:0回答:1

我有一个仅响应http2请求的url。

当我想用 python 向 URL 发送 http/2 请求时,我得到以下信息

ERROR
:

h2.exceptions.ProtocolError: Received duplicate pseudo-header field b':path'

我的

Code

from hyper.contrib import HTTP20Adapter
import requests
MyHeader={
    
  "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36",
   "X-Requested-With": "XMLHttpRequest"
    }

adapter = HTTP20Adapter(headers=MyHeader)
sessions=requests.session()
sessions.mount(prefix='https://myurl.com', adapter=adapter)
r=sessions.get('Continue_My_Url_response')
print(r)

我为

requests
使用了太多
HTTP/1
库,这是我第一次想与
HTTP/2
一起工作。

任何人都有通过

HTTP/2
发送此请求的想法和示例吗?

python python-3.x http2
1个回答
0
投票

在启用 http/2 支持的情况下使用 httpx:httpx.Client(http2=True)。

© www.soinside.com 2019 - 2024. All rights reserved.