I've got a list of 237 Ensembl protein IDs (e.g. ENSP00000493027), and I'm trying to convert them to UniProt accession numbers so that I can retrieve their REST text entry (e.g. https://rest.uniprot.org/uniprotkb/A0A286YF28.txt).
Officially, UniProt says to do it this way:
import urllib.parse
import urllib.request
url = 'https://www.uniprot.org/uploadlists/'
params = {
'from': 'ACC+ID',
'to': 'ENSEMBL_ID',
'format': 'tab',
'query': 'P40925 P40926 O43175 Q9UM73 P97793'
}
data = urllib.parse.urlencode(params)
data = data.encode('utf-8')
req = urllib.request.Request(url, data)
with urllib.request.urlopen(req) as f:
response = f.read()
print(response.decode('utf-8'))
However, when I run their example code verbatin, I get:
urllib.error.HTTPError: HTTP Error 405: Not Allowed
Along with some tracebacks. What's going on? It happens when I pass my own data too. Never used UniProt programmatically before.
Thanks in advance for any help anyone can give.
Awesome, thank you so much! This works; should be relatively straightforward to adapt to my application.