errdown 0.1.0a0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- errdown-0.1.0a0/.gitignore +11 -0
- errdown-0.1.0a0/LICENSE +202 -0
- errdown-0.1.0a0/NOTICE +7 -0
- errdown-0.1.0a0/PKG-INFO +40 -0
- errdown-0.1.0a0/README.md +23 -0
- errdown-0.1.0a0/pyproject.toml +27 -0
- errdown-0.1.0a0/src/errdown/__init__.py +10 -0
- errdown-0.1.0a0/src/errdown/_decide.py +37 -0
- errdown-0.1.0a0/src/errdown/_fingerprints.py +130 -0
- errdown-0.1.0a0/src/errdown/_headers.py +80 -0
- errdown-0.1.0a0/src/errdown/_normalize.py +476 -0
- errdown-0.1.0a0/src/errdown/_render.py +53 -0
- errdown-0.1.0a0/src/errdown/_status.py +72 -0
- errdown-0.1.0a0/src/errdown/_util.py +64 -0
- errdown-0.1.0a0/src/errdown/py.typed +0 -0
- errdown-0.1.0a0/tests/test_conformance.py +99 -0
errdown-0.1.0a0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
errdown-0.1.0a0/NOTICE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
errdown
|
|
2
|
+
Copyright 2026 Artem Zabarov
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
errdown is an independent project and is not affiliated with or endorsed by Cloudflare, Inc.
|
|
7
|
+
It follows Cloudflare's published structured error format for interoperability.
|
errdown-0.1.0a0/PKG-INFO
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: errdown
|
|
3
|
+
Version: 0.1.0a0
|
|
4
|
+
Summary: Cloudflare-compatible structured errors (RFC 9457) for every HTTP error your agent hits.
|
|
5
|
+
Project-URL: Homepage, https://errdown.com
|
|
6
|
+
Project-URL: Repository, https://github.com/ArtZab0/errdown
|
|
7
|
+
Author: Artem Zabarov
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
License-File: NOTICE
|
|
11
|
+
Keywords: ai-agents,cloudflare,errors,http,llm,mcp,problem-details,rfc9457
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Typing :: Typed
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# errdown
|
|
19
|
+
|
|
20
|
+
> **Pre-release (alpha).** API and output may change.
|
|
21
|
+
|
|
22
|
+
Cloudflare-compatible structured errors (RFC 9457 Problem Details) for every HTTP error your
|
|
23
|
+
agent hits: nginx, AWS, Vercel, framework defaults, JSON/XML API errors, bot challenges.
|
|
24
|
+
Zero dependencies, pure function, never throws. Independent project, not affiliated with Cloudflare.
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import httpx
|
|
28
|
+
from errdown import normalize, to_markdown, decide, agent_accept_header
|
|
29
|
+
|
|
30
|
+
res = httpx.get(url, headers={"accept": agent_accept_header()})
|
|
31
|
+
if res.is_error:
|
|
32
|
+
problem = normalize(res.status_code, res.headers, res.content, url=url)
|
|
33
|
+
if problem:
|
|
34
|
+
to_markdown(problem) # Cloudflare-format Markdown for the model
|
|
35
|
+
decide(problem) # {"action": "retry", "after_seconds": 5} | escalate | fail
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Spec and conformance fixtures: https://github.com/ArtZab0/errdown
|
|
39
|
+
|
|
40
|
+
License: Apache-2.0. Spec and fixtures: CC0 (captured third-party responses excepted).
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# errdown
|
|
2
|
+
|
|
3
|
+
> **Pre-release (alpha).** API and output may change.
|
|
4
|
+
|
|
5
|
+
Cloudflare-compatible structured errors (RFC 9457 Problem Details) for every HTTP error your
|
|
6
|
+
agent hits: nginx, AWS, Vercel, framework defaults, JSON/XML API errors, bot challenges.
|
|
7
|
+
Zero dependencies, pure function, never throws. Independent project, not affiliated with Cloudflare.
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
import httpx
|
|
11
|
+
from errdown import normalize, to_markdown, decide, agent_accept_header
|
|
12
|
+
|
|
13
|
+
res = httpx.get(url, headers={"accept": agent_accept_header()})
|
|
14
|
+
if res.is_error:
|
|
15
|
+
problem = normalize(res.status_code, res.headers, res.content, url=url)
|
|
16
|
+
if problem:
|
|
17
|
+
to_markdown(problem) # Cloudflare-format Markdown for the model
|
|
18
|
+
decide(problem) # {"action": "retry", "after_seconds": 5} | escalate | fail
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Spec and conformance fixtures: https://github.com/ArtZab0/errdown
|
|
22
|
+
|
|
23
|
+
License: Apache-2.0. Spec and fixtures: CC0 (captured third-party responses excepted).
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.24"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "errdown"
|
|
7
|
+
version = "0.1.0a0"
|
|
8
|
+
description = "Cloudflare-compatible structured errors (RFC 9457) for every HTTP error your agent hits."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
13
|
+
authors = [{ name = "Artem Zabarov" }]
|
|
14
|
+
keywords = ["rfc9457", "problem-details", "errors", "ai-agents", "llm", "mcp", "cloudflare", "http"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Typing :: Typed",
|
|
19
|
+
]
|
|
20
|
+
dependencies = []
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://errdown.com"
|
|
24
|
+
Repository = "https://github.com/ArtZab0/errdown"
|
|
25
|
+
|
|
26
|
+
[tool.hatch.build.targets.wheel]
|
|
27
|
+
packages = ["src/errdown"]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""errdown: Cloudflare-compatible structured errors (RFC 9457) for every HTTP error an agent hits.
|
|
2
|
+
|
|
3
|
+
Pre-release (alpha). Zero dependencies. `normalize()` never raises.
|
|
4
|
+
"""
|
|
5
|
+
from ._decide import agent_accept_header, backoff, decide
|
|
6
|
+
from ._normalize import normalize, sanitize
|
|
7
|
+
from ._render import ordered, to_json, to_markdown
|
|
8
|
+
|
|
9
|
+
__all__ = ["normalize", "to_markdown", "to_json", "ordered", "decide", "backoff", "agent_accept_header", "sanitize"]
|
|
10
|
+
__version__ = "0.1.0a0"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import random as _random
|
|
4
|
+
from typing import Any, Callable, Dict, Optional
|
|
5
|
+
|
|
6
|
+
_ESCALATE = {"challenge", "access_denied", "legal", "auth_required"}
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def decide(p: Dict[str, Any]) -> Dict[str, Any]:
|
|
10
|
+
"""Cloudflare's recommended control flow: retryable -> wait; owner action -> escalate; else fail fast."""
|
|
11
|
+
cat = p.get("error_category")
|
|
12
|
+
if cat == "challenge":
|
|
13
|
+
return {"action": "escalate", "reason": "challenge"}
|
|
14
|
+
if p.get("retryable"):
|
|
15
|
+
ra = p.get("retry_after")
|
|
16
|
+
return {"action": "retry", "after_seconds": 5 if ra is None else ra}
|
|
17
|
+
if p.get("owner_action_required"):
|
|
18
|
+
return {"action": "escalate", "reason": "owner_action_required"}
|
|
19
|
+
if cat in _ESCALATE:
|
|
20
|
+
return {"action": "escalate", "reason": cat}
|
|
21
|
+
return {"action": "fail", "reason": p.get("error_name")}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def backoff(attempt: int, *, base: float = 1, max: float = 60, min: float = 0,
|
|
25
|
+
random: Optional[Callable[[], float]] = None) -> float:
|
|
26
|
+
"""Exponential backoff with full jitter. attempt starts at 0. Honors a server-given minimum."""
|
|
27
|
+
rand = random or _random.random
|
|
28
|
+
ceiling = _min(max, base * 2 ** _max(0, attempt))
|
|
29
|
+
return _max(min, rand() * ceiling)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
_min, _max = min, max # keyword args above shadow the builtins inside backoff()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def agent_accept_header(mode: str = "markdown") -> str:
|
|
36
|
+
"""The Accept header Cloudflare recommends for agents."""
|
|
37
|
+
return "application/json, */*" if mode == "json" else "text/markdown, */*"
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""Port of packages/js/src/fingerprints.ts. Keep in the same order; JS `$` is written `\\Z`."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import re
|
|
5
|
+
from typing import Any, Dict, List, Optional
|
|
6
|
+
|
|
7
|
+
I = re.I
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _fp(id: str, source: str, confidence: float, *, status: Optional[List[int]] = None,
|
|
11
|
+
header: Optional[tuple] = None, body: Optional[List[Any]] = None, **over: Any) -> Dict[str, Any]:
|
|
12
|
+
return {"id": id, "source": source, "confidence": confidence, "status": status,
|
|
13
|
+
"header": (header[0], re.compile(header[1], header[2] if len(header) > 2 else 0)) if header else None,
|
|
14
|
+
"body": [re.compile(b) if isinstance(b, str) else re.compile(*b) for b in body] if body else None,
|
|
15
|
+
**over}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
CHALLENGES: List[Dict[str, Any]] = [
|
|
19
|
+
_fp("cloudflare_challenge", "cloudflare", 0.95, header=("cf-mitigated", r"challenge", I),
|
|
20
|
+
error_name="cloudflare_challenge", title="Bot verification required"),
|
|
21
|
+
_fp("cloudflare_challenge_page", "cloudflare", 0.9,
|
|
22
|
+
body=[(r"<title>Just a moment\.\.\.</title>|challenges\.cloudflare\.com|cf-chl-|_cf_chl_opt", I)],
|
|
23
|
+
error_name="cloudflare_challenge", title="Bot verification required"),
|
|
24
|
+
_fp("recaptcha", "unknown", 0.85,
|
|
25
|
+
body=[(r"google\.com/recaptcha|g-recaptcha", I), (r"captcha|verify you are human|unusual traffic", I)],
|
|
26
|
+
error_name="recaptcha_challenge", title="CAPTCHA required"),
|
|
27
|
+
_fp("hcaptcha", "unknown", 0.85, body=[(r"hcaptcha\.com|h-captcha", I)],
|
|
28
|
+
error_name="hcaptcha_challenge", title="CAPTCHA required"),
|
|
29
|
+
_fp("aws_waf_captcha", "aws-cloudfront", 0.9, header=("x-amzn-waf-action", r"captcha|challenge", I),
|
|
30
|
+
error_name="aws_waf_challenge", title="Bot verification required"),
|
|
31
|
+
_fp("datadome", "unknown", 0.85, header=("x-datadome", r"."),
|
|
32
|
+
body=[(r"captcha-delivery\.com|datadome", I)],
|
|
33
|
+
error_name="datadome_challenge", title="Bot verification required"),
|
|
34
|
+
_fp("perimeterx", "unknown", 0.85, body=[(r"px-captcha|perimeterx|_pxCaptcha", I)],
|
|
35
|
+
error_name="perimeterx_challenge", title="Bot verification required"),
|
|
36
|
+
_fp("indeed_bot_detection", "unknown", 0.85, body=[(r"from=bot-detection", I)],
|
|
37
|
+
error_name="bot_detection_redirect", title="Bot verification required"),
|
|
38
|
+
_fp("linkedin_999", "linkedin", 0.85, status=[999], header=("x-li-fabric", r"."),
|
|
39
|
+
error_name="linkedin_bot_block", title="Blocked as automated traffic"),
|
|
40
|
+
_fp("network_security_block", "unknown", 0.85, status=[403], body=[(r"blocked by network security", I)],
|
|
41
|
+
category="access_denied", error_name="network_security_block", title="Blocked by network security"),
|
|
42
|
+
_fp("akamai_bot", "akamai", 0.8, status=[403],
|
|
43
|
+
body=[(r"<title>Access Denied</title>", I), (r"Reference #[0-9]+\.[0-9a-f]+", I)],
|
|
44
|
+
category="access_denied", error_name="akamai_access_denied", title="Access denied"),
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
PAGES: List[Dict[str, Any]] = [
|
|
48
|
+
_fp("cloudflare_blocked", "cloudflare", 0.9,
|
|
49
|
+
body=[(r"cf-error-details", I), (r"Sorry, you have been blocked", I)],
|
|
50
|
+
category="access_denied", error_name="cloudflare_blocked", title="Blocked by the site's firewall",
|
|
51
|
+
retryable=False, owner_action_required=False,
|
|
52
|
+
detail="The site's Cloudflare firewall blocked this request."),
|
|
53
|
+
_fp("cloudflare_legacy", "cloudflare", 0.9, body=[(r"cf-error-details|cf-wrapper|Cloudflare Ray ID", I)]),
|
|
54
|
+
_fp("nginx_default", "nginx", 0.9, body=[(r"<center>nginx(/[0-9.]+)?</center>", I)]),
|
|
55
|
+
_fp("apache_default", "apache", 0.9, body=[(r"<address>Apache(/[0-9.]+)?[^<]*Server at", I)]),
|
|
56
|
+
_fp("apache_header", "apache", 0.7, header=("server", r"^Apache", I),
|
|
57
|
+
body=[(r"<title>[0-9]{3} [^<]+</title>", I)]),
|
|
58
|
+
_fp("caddy", "caddy", 0.75, header=("server", r"^Caddy", I)),
|
|
59
|
+
_fp("envoy_upstream", "envoy", 0.9,
|
|
60
|
+
body=[(r"upstream connect error or disconnect/reset before headers|no healthy upstream", I)],
|
|
61
|
+
category="upstream_unavailable", error_name="envoy_upstream_unavailable",
|
|
62
|
+
title="Upstream unavailable", retryable=True),
|
|
63
|
+
_fp("envoy_timeout", "envoy", 0.9, body=[r"^upstream request timeout\s*\Z"],
|
|
64
|
+
category="upstream_unavailable", error_name="envoy_upstream_timeout",
|
|
65
|
+
title="Upstream timeout", retryable=True),
|
|
66
|
+
_fp("envoy_empty", "envoy", 0.75, header=("server", r"^envoy\Z", I), body=[r"^\s*\Z"]),
|
|
67
|
+
_fp("traefik_404", "traefik", 0.8, body=[r"^404 page not found\s*\Z"]),
|
|
68
|
+
_fp("traefik", "traefik", 0.65,
|
|
69
|
+
body=[r"^(Bad Gateway|Gateway Timeout|Service Unavailable|Too Many Requests|Request Entity Too Large)\s*\Z"]),
|
|
70
|
+
_fp("aws_alb", "aws-alb", 0.9, header=("server", r"^awselb", I)),
|
|
71
|
+
_fp("aws_apigateway", "aws-apigateway", 0.85, header=("x-amzn-errortype", r".")),
|
|
72
|
+
_fp("aws_cloudfront", "aws-cloudfront", 0.9, body=[(r"Generated by cloudfront \(CloudFront\)", I)]),
|
|
73
|
+
_fp("vercel", "vercel", 0.85, header=("x-vercel-error", r".")),
|
|
74
|
+
_fp("vercel_hosted", "vercel", 0.6, header=("x-vercel-id", r".")),
|
|
75
|
+
_fp("github_pages", "github-pages", 0.85, status=[404], header=("server", r"^GitHub\.com\Z", I),
|
|
76
|
+
body=[(r"GitHub Pages|There isn't a GitHub Pages site here|Site not found", I)]),
|
|
77
|
+
_fp("netlify", "netlify", 0.8, header=("server", r"^Netlify", I)),
|
|
78
|
+
_fp("heroku_no_such_app", "heroku", 0.95, body=[(r"<title>No such app</title>", I)],
|
|
79
|
+
category="not_found", error_name="heroku_no_such_app", title="No such app",
|
|
80
|
+
retryable=False, detail="There is no Heroku app at this address."),
|
|
81
|
+
_fp("heroku_app_error", "heroku", 0.9,
|
|
82
|
+
body=[(r"herokucdn\.com/error-pages|Application error", I), (r"heroku", I)],
|
|
83
|
+
category="server_error", error_name="heroku_application_error",
|
|
84
|
+
title="Application error", retryable=True),
|
|
85
|
+
_fp("render_no_server", "render", 0.9, header=("x-render-routing", r"no-server", I),
|
|
86
|
+
category="not_found", error_name="render_no_server", title="No service at this address",
|
|
87
|
+
detail="There is no Render service at this address."),
|
|
88
|
+
_fp("render", "render", 0.75, header=("x-render-origin-server", r".")),
|
|
89
|
+
_fp("gfe_default", "google-frontend", 0.8,
|
|
90
|
+
body=[(r"<h1>Error: (Page )?Not Found</h1>", I), (r"The requested URL was not found on this server", I)]),
|
|
91
|
+
_fp("google_404", "google-frontend", 0.8, body=[r"<title>Error 404 \(Not Found\)!!1</title>"]),
|
|
92
|
+
_fp("gfe", "google-frontend", 0.8, header=("server", r"^(Google Frontend|GFE|gws)", I)),
|
|
93
|
+
_fp("express_default", "express", 0.85, header=("x-powered-by", r"^Express\Z", I),
|
|
94
|
+
body=[(r"<title>Error</title>", I), (r"<pre>", I)]),
|
|
95
|
+
_fp("werkzeug_default", "werkzeug", 0.85,
|
|
96
|
+
body=[(r"<title>[0-9]{3} [^<]+</title>\s*<h1>[^<]+</h1>\s*<p>", I),
|
|
97
|
+
(r"(If you entered the URL manually please check your spelling|The server encountered an internal error and was unable to complete your request|You don't have the permission to access the requested resource)", I)]),
|
|
98
|
+
_fp("django_default", "django", 0.85,
|
|
99
|
+
body=[(r"(<title>Server Error \(500\)</title>|The requested resource was not found on this server\.|<title>403 Forbidden</title>[\s\S]{0,200}<h1>403 Forbidden</h1>)", I)]),
|
|
100
|
+
_fp("tomcat_default", "tomcat", 0.9, body=[r"<title>HTTP Status [0-9]{3} – [^<]+</title>"]),
|
|
101
|
+
_fp("jetty_default", "jetty", 0.9, body=[r"<h2>HTTP ERROR [0-9]{3}"]),
|
|
102
|
+
_fp("python_http_server", "python-http-server", 0.8,
|
|
103
|
+
body=[r"<title>Error response</title>", r"Error code explanation:"]),
|
|
104
|
+
_fp("uvicorn_plain", "uvicorn", 0.7, header=("server", r"^uvicorn\Z", I),
|
|
105
|
+
body=[r"^(Internal Server Error|Not Found|Method Not Allowed)\s*\Z"]),
|
|
106
|
+
_fp("envoy_plain", "envoy", 0.75, header=("server", r"^envoy\Z", I), body=[r"^[A-Z][A-Za-z -]{2,40}\Z"]),
|
|
107
|
+
_fp("fastly", "fastly", 0.8, body=[(r"Varnish cache server|Fastly error", I)]),
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def matches(fp: Dict[str, Any], status: int, h: Dict[str, str], body: str) -> bool:
|
|
112
|
+
if fp["status"] and status not in fp["status"]:
|
|
113
|
+
return False
|
|
114
|
+
if fp["header"]:
|
|
115
|
+
name, pat = fp["header"]
|
|
116
|
+
v = h.get(name)
|
|
117
|
+
if v is None or not pat.search(v):
|
|
118
|
+
return False
|
|
119
|
+
if fp["body"]:
|
|
120
|
+
for rx in fp["body"]:
|
|
121
|
+
if not rx.search(body):
|
|
122
|
+
return False
|
|
123
|
+
return bool(fp["header"] or fp["body"])
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def find_fingerprint(lst: List[Dict[str, Any]], status: int, h: Dict[str, str], body: str) -> Optional[Dict[str, Any]]:
|
|
127
|
+
for fp in lst:
|
|
128
|
+
if matches(fp, status, h, body):
|
|
129
|
+
return fp
|
|
130
|
+
return None
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from datetime import datetime, timezone
|
|
5
|
+
from email.utils import parsedate_to_datetime
|
|
6
|
+
from typing import Any, Dict, Optional
|
|
7
|
+
|
|
8
|
+
from ._util import js_round
|
|
9
|
+
|
|
10
|
+
HeaderMap = Dict[str, str]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def to_header_map(h: Any) -> HeaderMap:
|
|
14
|
+
"""Accepts dict, list of pairs, or anything with .items() (httpx/requests/aiohttp headers)."""
|
|
15
|
+
m: HeaderMap = {}
|
|
16
|
+
if not h:
|
|
17
|
+
return m
|
|
18
|
+
|
|
19
|
+
def put(k: Any, v: Any) -> None:
|
|
20
|
+
if not isinstance(k, str) or v is None:
|
|
21
|
+
return
|
|
22
|
+
m[k.lower()] = ", ".join(str(x) for x in v) if isinstance(v, (list, tuple)) else str(v)
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
if hasattr(h, "multi_items"): # httpx: keep repeated headers
|
|
26
|
+
seen: Dict[str, list] = {}
|
|
27
|
+
for k, v in h.multi_items():
|
|
28
|
+
seen.setdefault(k.lower(), []).append(v)
|
|
29
|
+
for k, vs in seen.items():
|
|
30
|
+
put(k, vs if len(vs) > 1 else vs[0])
|
|
31
|
+
elif hasattr(h, "items"):
|
|
32
|
+
for k, v in h.items():
|
|
33
|
+
put(k, v)
|
|
34
|
+
else:
|
|
35
|
+
for pair in h:
|
|
36
|
+
if isinstance(pair, (list, tuple)) and len(pair) >= 2:
|
|
37
|
+
put(pair[0], pair[1])
|
|
38
|
+
except Exception:
|
|
39
|
+
pass
|
|
40
|
+
return m
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
_MAX_RETRY = 86400
|
|
44
|
+
_DIGITS = re.compile(r"[0-9]+\Z")
|
|
45
|
+
_NUM = re.compile(r"[0-9]+(\.[0-9]+)?\Z")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _clamp(n: float) -> int:
|
|
49
|
+
return max(0, min(_MAX_RETRY, js_round(n)))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _parse_date_ms(s: str) -> Optional[float]:
|
|
53
|
+
try:
|
|
54
|
+
dt = parsedate_to_datetime(s)
|
|
55
|
+
except Exception:
|
|
56
|
+
dt = None
|
|
57
|
+
if dt is None:
|
|
58
|
+
try:
|
|
59
|
+
dt = datetime.fromisoformat(s.replace("Z", "+00:00"))
|
|
60
|
+
except Exception:
|
|
61
|
+
return None
|
|
62
|
+
if dt.tzinfo is None:
|
|
63
|
+
dt = dt.replace(tzinfo=timezone.utc)
|
|
64
|
+
return dt.timestamp() * 1000
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def retry_after_from_headers(h: HeaderMap, now_ms: float) -> Optional[int]:
|
|
68
|
+
ra = (h.get("retry-after") or "").strip()
|
|
69
|
+
if ra:
|
|
70
|
+
if _DIGITS.match(ra):
|
|
71
|
+
return _clamp(int(ra))
|
|
72
|
+
t = _parse_date_ms(ra)
|
|
73
|
+
if t is not None:
|
|
74
|
+
return _clamp((t - now_ms) / 1000)
|
|
75
|
+
for name in ("ratelimit-reset", "x-ratelimit-reset", "x-rate-limit-reset"):
|
|
76
|
+
v = (h.get(name) or "").strip()
|
|
77
|
+
if v and _NUM.match(v):
|
|
78
|
+
n = float(v)
|
|
79
|
+
return _clamp(n - now_ms / 1000 if n > 1e9 else n)
|
|
80
|
+
return None
|