I keep getting a "too many requests error" when querying the NCBI SRA database, even though I'm running less than 10 requests per second, and I have an API key, which supposedly should allow me to run 10 per second.
Here is my (Python) code:
import subprocess
import concurrent.futures
import time
bioprojects = [
"PRJNA644722",
"PRJNA644892"
]
all_metadata_generators = []
def fetch_metadata(bioproject):
return subprocess.run(f"esearch -db sra -query '{bioproject}[bioproject]' | efetch -format runinfo", shell=True, capture_output=True, text=True)
with concurrent.futures.ThreadPoolExecutor() as executor:
for i in range(0, len(bioprojects), 10):
all_metadata_generators.append(executor.map(fetch_metadata, bioprojects[i:i+10]))
time.sleep(1)
for metadata_generator in all_metadata_generators:
for metadata in metadata_generator:
print(metadata)
sleep
, I would just increase it until the signal detection police are happy. If you use a try: exception loop you could even try and attempt to attenuate thesleep
time to just about the detection limit. Goodluck $\endgroup$sleep
is technically not even doing anything since I only have 2 bioproject ids. So I can't even do 2 requests in more than one second without problems $\endgroup$.bashrc
file? I would run the same command from the command line to check if you still get the 429 error. If you don't then you may have to specify the API key in the python command again. $\endgroup$