GeneGPT icon indicating copy to clipboard operation
GeneGPT copied to clipboard

is it correct in the call_api(url) function to replace " " with "+"?

Open lonelyhwy opened this issue 1 year ago • 3 comments

In main.py, the function call_api. There is a statement: url = url.replace(' ', '+') I have tried the example URL in Demonstration 1 (Dm. 1). https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&retmax=5&retmode=json&sort=relevance&term=LMP10. It seems correct(result is same as Demonstration 1)

Then if I add a between "?" and "db" in this URL, and use the call_api() function. It will be replaced like this: https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?+db=gene&retmax=5&retmode=json&sort=relevance&term=LMP10 Then the result is not the same as Demonstration 1.

So I want to know why you want to replace " " with "+"? Thanks

lonelyhwy avatar Jun 07 '24 03:06 lonelyhwy

URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.

Andy-jqa avatar Jun 07 '24 03:06 Andy-jqa

I know. But replacing spaces with "+" cannot give you the right answer in the E-utils APIs. Why not replace it with ""(empty) ?

lonelyhwy avatar Jun 07 '24 04:06 lonelyhwy

That might cause parsing issues for the API? If you don't have spaces between words sometimes the service returns nothing.

Andy-jqa avatar Jun 08 '24 14:06 Andy-jqa

Another option is to replace with %20. Ultimately you want to do a HTML decode / escape, which is standardized. I have a feeling Python has some functions for that. There are two "levels" of escaping, one which takes query parameters into account, and the other encodes those too.

MrCsabaToth avatar Jan 15 '25 16:01 MrCsabaToth