This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Fetching records using Entrez

I want to fetch 1000 records from 2023 onwards and records of 2015 and before them from the Pubmed using Entrez python. I went through the docs, but I am way too much confused. I tried using Blackbox and chatGPT to debug but still I am facing errors. Here is my code;

search_results = Entrez.read(
    Entrez.esearch(
        db = "pubmed", term = query, datetype = "pdat", usehistory = "y"
    )
)
count = int(search_results["Count"])
print("Found %i results" % count)

batch_size = 10
output = open("recent_orchid_papers.txt", "w")
for start in range(0, count, batch_size):
    end = min(int(search_results["Count"]), start + batch_size)
    handle = Entrez.efetch(db = "pubmed", rettype = "abstract", retmode = "text", retstart = start, retmax = batch_size, webenv = search_results["WebEnv"], query_key = search_results["QueryKey"])
    abstracts = handle.read()
    handle.close()
    print(abstracts)

The error was shown to be in the line- Entrez.esearch() and the error was- HTTP error 400 bad request. Please help me resolve the issue and explain me my error and how can I write the correct code to fetch the records from Pubmed.

python pubmed entrez

What's your exact query string?

0 answers

No answers yet.

Log in to answer this question.