codesearch-py icon indicating copy to clipboard operation
codesearch-py copied to clipboard

Server requests return HTML due to redirect to new codesearch

Open jessemckenna opened this issue 4 years ago • 2 comments

API requests currently return HTML instead of JSON, resulting in an error. @asankah advised that this is due to requests to cs.chromium.org being redirected to the new codesearch at source.chromium.org, which now requires an API key.

For example, this test script:

g_cs = codesearch.CodeSearch(should_cache=True, source_root='.')
response = g_cs.SendRequestToServer(codesearch.CompoundRequest(
    search_request=[
    codesearch.SearchRequest(query='hello world',
                             return_line_matches=True,
                             lines_context=0,
                             max_num_results=10)
    ]))

Currently hits this error:

Traceback (most recent call last):
  File "C:\Users\jessemckenna\AppData\Roaming\Sublime Text 3\Packages\ChromiumXRefs\third_party\codesearch\messages.py", line 204, in FromJsonString
    d = json.loads(s)
  File "C:\src\depot_tools\bootstrap-3_8_0_chromium_8_bin\python3\bin\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\src\depot_tools\bootstrap-3_8_0_chromium_8_bin\python3\bin\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\src\depot_tools\bootstrap-3_8_0_chromium_8_bin\python3\bin\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Printing the server response, result, from SendRequestToServer before it is passed to FromJSONString shows an HTML response from source.chromium.org.

jessemckenna avatar Apr 06 '20 15:04 jessemckenna

Hello,

I got here by searching for "Chromium Code Search API" in Google. I was using this script a few years ago, to quickly get a list of inherited CSS properties and maintain this document. I understood that searching in the Chromium codebase now inloves using a private "Contents API".

Since you both seem to work at Google, can you please just tell me if there's an "official" way to achieve the task described above?

cdoublev avatar Aug 08 '20 07:08 cdoublev

Unfortunately there isn't an official API for that.

This code was also using an unofficial and unsupported endpoint which is no longer available.

On Sat, Aug 8, 2020 at 3:37 AM Guillaume [email protected] wrote:

Hello,

I got here by searching for "Chromium Code Search API" in Google. I was using this script a few years ago, to quickly get a list of inherited CSS properties and maintain this document. I understood that searching in the Chromium codebase now inloves using a private "Contents API".

Since you both seem to work at Google, can you please just tell me if there's an "official" way to achieve the task described above?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/chromium/codesearch-py/issues/30#issuecomment-670839507, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABGQSLF72AFH2HESBC67ITR7T6ETANCNFSM4MCLW4AQ .

asankah avatar Aug 08 '20 18:08 asankah