Requests `Session.request` assumes url to be `str`
@NathanielRN 已经在做这个了。
开始于 2022年3月21日。
评估
这个 Issue 还没有评估数据。
描述
https://github.com/aws/aws-xray-sdk-python/blob/f5f9c470b189bb34f31a1d0a28f497741132b7d2/aws_xray_sdk/ext/requests/patch.py#L23
Implicitly assumes the url to be str.
In the case where you have bytes as the url (allowed by requests in stubs https://github.com/python/typeshed/blob/master/stubs/requests/requests/sessions.pyi#L88 and works fine in runtime. The official docs however don't specify a specific type https://github.com/psf/requests/blob/79f60274f7e461b8fd2f579e741f748438d7eadb/requests/sessions.py#L465) the variable goes through the following path leading to an TypeError when sampling is enabled.
https://github.com/aws/aws-xray-sdk-python/blob/f5f9c470b189bb34f31a1d0a28f497741132b7d2/aws_xray_sdk/ext/util.py#L131
Returns parsed url with type(url.hostname) -> bytes.
https://github.com/aws/aws-xray-sdk-python/blob/f5f9c470b189bb34f31a1d0a28f497741132b7d2/aws_xray_sdk/core/recorder.py#L425
Passed without any changes to report_subsegment.
https://github.com/aws/aws-xray-sdk-python/blob/f5f9c470b189bb34f31a1d0a28f497741132b7d2/aws_xray_sdk/core/recorder.py#L276
And from there passed to begin_subsegment unchanged. Here types declared in docstrings are not followed.
https://github.com/aws/aws-xray-sdk-python/blob/f5f9c470b189bb34f31a1d0a28f497741132b7d2/aws_xray_sdk/core/models/subsegment.py#L81
Then the name passes to Subsegment if sampling is enabled.
https://github.com/aws/aws-xray-sdk-python/blob/f5f9c470b189bb34f31a1d0a28f497741132b7d2/aws_xray_sdk/core/models/entity.py#L30
super().__init__ is called and we end up in Entity.__init__ with the unchanged name with type bytes.
https://github.com/aws/aws-xray-sdk-python/blob/f5f9c470b189bb34f31a1d0a28f497741132b7d2/aws_xray_sdk/core/models/entity.py#L38
Then at this line we're iterating over the items in the bytes (type(c) -> int) and checking if those are included in an str and we get a TypeError.
File "/var/task/aws_xray_sdk/ext/requests/patch.py", line 27, in _xray_traced_requests
return xray_recorder.record_subsegment(
File "/var/task/aws_xray_sdk/core/recorder.py", line 428, in record_subsegment
subsegment = self.begin_subsegment(name, namespace)
File "/var/task/aws_xray_sdk/core/recorder.py", line 300, in begin_subsegment
subsegment = Subsegment(name, namespace, segment)
File "/var/task/aws_xray_sdk/core/models/subsegment.py", line 98, in __init__
super(Subsegment, self).__init__(name)
File "/var/task/aws_xray_sdk/core/models/entity.py", line 38, in __init__
self.name = ''.join([c for c in name if c not in _common_invalid_name_characters])
File "/var/task/aws_xray_sdk/core/models/entity.py", line 38, in <listcomp>
self.name = ''.join([c for c in name if c not in _common_invalid_name_characters])
TypeError: 'in <string>' requires string as left operand, not int
The best fix is probably to sanitize the hostname once getting that off from urlparse and convert it to an str.
- 主要语言
- Python
- 星标
- 339
- 派生
- 147
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
aws/aws-xray-sdk-python 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 68/100
aws/aws-xray-sdk-python#490 · 1 条评论 ·
-
难度 5/5 一周以上 新手友好度 1/100
aws/aws-xray-sdk-python#460 ·
-
Next release未关闭
难度 5/5 一周以上 新手友好度 20/100
aws/aws-xray-sdk-python#457 · 1 个 reaction ·
-
难度 3/5 1-2 天 新手友好度 35/100
aws/aws-xray-sdk-python#453 ·
-
难度 4/5 3-5 天 新手友好度 35/100
aws/aws-xray-sdk-python#452 · 1 个 reaction ·
查看 aws/aws-xray-sdk-python 的全部 Issue
相似的 Issue
-
pydanty:is-working
难度 2/5 1-3 小时 新手友好度 78/100
pydantic/pydantic-ai#8843 ·
维护者通常 1 天内回复
-
breaking change enhancement server
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
needs-triage
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复