You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用gql调用GraphQL API时遇aiohttp HTTP头换行安全错误求助

使用gql调用GraphQL API时遇到HTTP头安全错误的求助

我正在使用gql调用GraphQL API,出现如下错误:

File "<path to poetry venv>/lib/python3.10/site-packages/aiohttp/http_writer.py", line 129, in write_headers
    buf = _serialize_headers(status_line, headers)
File "aiohttp/_http_writer.pyx", line 132, in aiohttp._http_writer._serialize_headers
File "aiohttp/_http_writer.pyx", line 116, in aiohttp._http_writer._safe_header
ValueError: Newline or carriage return character detected in HTTP status message or header. This is a potential security issue.

我已了解到这是HTTP头或状态信息中包含换行/回车符触发的安全校验问题,但我并未手动设置任何请求头,只是运行类似如下代码:

from gql import Client as gql_client, gql

expr_ = '''mutation myMutation($var: Type) {
             nameOfMyGraphQLMutation(var: $var) {
              ... (fields to return) ...
             }
           }'''
expr = gql(expr_)
client = gql_client(...)
client.execute(expr, ...)

注意到gql内部依赖aiohttp,我曾尝试修改虚拟环境中的aiohttp代码来定位有问题的请求头,但发现相关代码是编译后的文件(如_http_writer.cpython-310-darwin.so),本地修改无法生效。谷歌搜索后未找到其他开发者遇到相同问题,推测问题出在我这边,请问该如何解决?

内容的提问来源于stack exchange,提问作者ssc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 12:33:26