Getting the options in a http request status 300

Question:

I read that when I get this error I should specify better the url. I assume that I should specify between two displayed or accessible options. How can I do that?

In urllib or its tutorial I couldn’t find anything. My assumption is true? Can I read somewhere the possible url?

When I open this url in my browser I am redirected to a new url.

The url I try to access: http://www.uniprot.org/uniprot/P08198_CSG_HALHA.fasta
The new url I am redirected: http://www.uniprot.org/uniprot/?query=replaces:P08198&format=fasta

import urllib.request
try:
    response = urllib.request.urlopen(url)
except urllib.error.HTTPError as e:
    if int(e.code) == 300:
        # what now?
Asked By: llrs

||

Answers:

The status code 300 is returned from the server to tell you, your request is somehow not complete and you shall be more specific.

Testing the url, I tried to search from http://www.uniprot.org/ and entered into search “P08198”. This resulted in page http://www.uniprot.org/uniprot/P08198 telling me

Demerged into Q9HM69, B0R8E4 and P0DME1. [ List ] 

To me it seems, the query for some protein is not specific enough as this protein code was split to subcategories or subcodes Q9HM69, B0R8E4 and P0DME1.

Conclusion

Status code 300 is signal from server app, that your request is somehow ambiguous. The way, you can make it specific enough is application specific and has nothing to do with Python or HTTP status codes, you have to find more details about good url in the application logic.

Answered By: Jan Vlcinsky

So I ran into this issue and wanted to get the actual content returned.

turns out that this is the solution to my problem.

import urllib.request
try:
    response = urllib.request.urlopen(url)
except urllib.error.HTTPError as e:
    if int(e.code) == 300:
        response = r.read()
Answered By: John Kearney