antlr / antlr/antlr4-tools

Bad request on central.sonatype.com

Open Beginner friendly
#22 15 comments 8 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
118
Forks
30
PR merge metrics
No merged PRs in 30d

Description

Hello guys,

Just to let you known that there seems to be some sort of regression on #18, as in the last two days I started getting a timeout on the `https://central.sonatype.com/solrsearch/select?q=a:antlr4-master+g:org.antlr` (it returns a 400 status), but if I use the `search.maven.com` domain the query works.

```
Could not get latest version number, attempting to fall back to latest downloaded version...
Traceback (most recent call last):
File "/usr/local/lib/python3.14/site-packages/antlr4_tool_runner.py", line 26, in latest_version
with urlopen("https://central.sonatype.com/solrsearch/select?q=a:antlr4-master+g:org.antlr",
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
timeout=10) as response:
^^^^^^^^^^^
File "/usr/local/lib/python3.14/urllib/request.py", line 187, in urlopen
return opener.open(url, data, timeout)
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.14/urllib/request.py", line 493, in open
response = meth(req, response)
File "/usr/local/lib/python3.14/urllib/request.py", line 602, in http_response
response = self.parent.error(
'http', request, response, code, msg, hdrs)
File "/usr/local/lib/python3.14/urllib/request.py", line 531, in error
return self._call_chain(*args)
~~~~~~~~~~~~~~~~^^^^^^^
File "/usr/local/lib/python3.14/urllib/request.py", line 464, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.14/urllib/request.py", line 611, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400:

```

The issue with `central.sonatype.com` seems to be specifically with the `+` operation, as the query works for each term individually.

On another note, looking at the FAQ at https://central.sonatype.org/faq/what-happened-to-search-maven-org/#what-about-the-searchmavenorg-api it seems that the `search.maven.com` domain is still the one to be used for API calls, as the redirect seems to be targeting the web browser traffic, but I am not familiar with these services.

For the time being the fix below works, but not sure if this is the best way going forward to prevent these issues in the future (again, not familiar with these services):

```
diff --git a/antlr4_tool_runner.py b/antlr4_tool_runner.py
index 9903e94..281f80b 100644
--- a/antlr4_tool_runner.py
+++ b/antlr4_tool_runner.py
@@ -23,7 +23,7 @@ def initialize_paths():

def latest_version():
try:
- with urlopen("https://central.sonatype.com/solrsearch/select?q=a:antlr4-master+g:org.antlr",
+ with urlopen("https://search.maven.org/solrsearch/select?q=a:antlr4-master+g:org.antlr",
timeout=10) as response:
s = response.read().decode("UTF-8")
searchResult = json.loads(s)['response']
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in antlr4_tool_runner.py at latest_version() and reproduce the query against both central.sonatype.com and search.maven.org, using the FAQ link for API guidance. Confirm which endpoint accepts the combined query and that the response still has the expected JSON structure; done means latest-version lookup succeeds without the HTTP 400 regression.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.