Skip to content

Commit c9ebe17

Browse files
sjarmakclaude
andcommitted
fix: add User-Agent header to SG API requests (Cloudflare 1010 block)
Python's default urllib User-Agent was being blocked by Cloudflare, causing all SG API calls to return 403. Add ccb-context-retrieval-agent/1.0 User-Agent via centralized _headers() method. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 84a4142 commit c9ebe17

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

scripts/context_retrieval_agent.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ def __init__(self, url: str = "", token: str = ""):
173173
# Validate token at init
174174
self._validate_token()
175175

176+
def _headers(self) -> dict:
177+
"""Standard headers for SG API requests (includes User-Agent to avoid Cloudflare 1010)."""
178+
return {
179+
"Authorization": f"token {self.token}",
180+
"Content-Type": "application/json",
181+
"User-Agent": "ccb-context-retrieval-agent/1.0",
182+
}
183+
176184
def _validate_token(self) -> None:
177185
"""Check that the token is valid by running a simple query."""
178186
import urllib.request
@@ -183,10 +191,7 @@ def _validate_token(self) -> None:
183191
req = urllib.request.Request(
184192
f"{self.url.rstrip('/')}/.api/graphql",
185193
data=body,
186-
headers={
187-
"Authorization": f"token {self.token}",
188-
"Content-Type": "application/json",
189-
},
194+
headers=self._headers(),
190195
)
191196
try:
192197
with urllib.request.urlopen(req, timeout=10) as resp:
@@ -227,10 +232,7 @@ def keyword_search(self, query: str, max_results: int = 50) -> str:
227232
req = urllib.request.Request(
228233
f"{self.url.rstrip('/')}/.api/graphql",
229234
data=body,
230-
headers={
231-
"Authorization": f"token {self.token}",
232-
"Content-Type": "application/json",
233-
},
235+
headers=self._headers(),
234236
)
235237
try:
236238
with urllib.request.urlopen(req, timeout=30) as resp:

0 commit comments

Comments
 (0)