reut
reut

Reputation: 21

Error when using NCBIWWW from biopython

I am trying to blast nucleotide sequence using NCBIWWW

from Bio.Blast import NCBIWWW
my_query = "TGCGTGCCGTGCAATGTGCGT"
result_handle = NCBIWWW.qblast("blastn", "nt", my_query)
blast_result = open("my_blast.xml", "w") 
blast_result.write(result_handle.read())
blast_result.close()
result_handle.close()

This was working well for the fist time, but when I tried to run it few days later I got an error:

>     result_handle = NCBIWWW.qblast("blastn", "nt", my_query)   File "/usr/local/lib/python2.7/dist-packages/biopython-1.63-py2.7-linux-x86_64.egg/Bio/Blast/NCBIWWW.py", line 123, in qblast
>     handle = _urlopen(request)   File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
>     return _opener.open(url, data, timeout)   File "/usr/lib/python2.7/urllib2.py", line 410, in open
>     response = meth(req, response)   File "/usr/lib/python2.7/urllib2.py", line 523, in http_response
>     'http', request, response, code, msg, hdrs)   File "/usr/lib/python2.7/urllib2.py", line 448, in error
>     return self._call_chain(*args)   File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
>     result = func(*args)   File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default
>     raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 403: Forbidden

I didn't change anything in the code so I don't understand what happened. What can be the problem?

Thanks!

Upvotes: 2

Views: 1821

Answers (2)

user3732664
user3732664

Reputation: 101

I had the same error coming up using blastn. Looks like NCBI have moved from http to https (https://www.ncbi.nlm.nih.gov/home/develop/https-guidance.shtml). If you follow the link you'll see that you need Biopython version 1.67 or higher to use NCBIWWW now. I've just upgraded to biopython 1.68 and this has fixed my issue, hope that helps you too.

Upvotes: 1

Sweasonable Doubt
Sweasonable Doubt

Reputation: 98

I got the exact same error message recently when I tried to use qblast on the protein database.

The fix:

I went to the Biopython github and got the source code for the qblast module.

https://github.com/biopython/biopython/blob/master/Bio/Blast/NCBIWWW.py

I opened it up in a text editor and added a simple script to the end

fasta_string = open("test500.fasta").read()

result_handle = qblast(
"blastp",
"swissprot",
fasta_string,
)
save_file = open("out.xml", "w")

save_file.write(result_handle.read())

save_file.close()

result_handle.close()

I then ran the whole program, and got the results I had gotten previously. Note that you don't need the import statements any more. In fact, it won't work if you have them. You're defining the function in your script now.

I am not sure why this is an issue now, but NCBI did make some formatting changes recently, so it might be related to that. Any clarification would be appreciate as I know this is more of script-kiddie work around than a solution.

Upvotes: 1

Related Questions