0

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?
Community
  • 1
  • 1
llrs
  • 3,308
  • 35
  • 68

2 Answers2

0

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.

Jan Vlcinsky
  • 42,725
  • 12
  • 101
  • 98
  • Then there is no way thorough python to get the links to these other urls? And I should do it manually? – llrs May 26 '14 at 09:01
  • The app might return this page, in that case you could search through the content and collect the links to follow. This task is in two steps: first - get the page (it does not matter the page returned non 200 code), then - parse the page and search for offered urls. – Jan Vlcinsky May 26 '14 at 09:04
  • Sorry, but I am not sure I will be able to do that alone, could you point me some sources to learn to do it? When I print(e.code) I just can read `b''`. So I don't know if I should get it some other way or I am using wrongly the library. – llrs May 26 '14 at 09:07
  • 1
    @Llopis For fetching the page, you have to do your own experiments to lear, which URL shows the page with options to follow. For parsing final page, you might try `lxml` or `beautifoulsoup`, I would try `lxml`, see http://lxml.de/parsing.html . If in troubles, post another question. – Jan Vlcinsky May 26 '14 at 09:41
0

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()
John Kearney
  • 322
  • 3
  • 9