title: How can I talk to UniProt over HTTP in Python?
body: <p>I'm trying to get some results from UniProt, which is a protein database (details are not important). I'm trying to use some script that translates from one kind of ID to another. I was able to do this manually on the browser, but could not do it in Python. </p>
  
  <p>In <a href="http://www.uniprot.org/faq/28" rel="noreferrer">http://www.uniprot.org/faq/28</a> there are some sample scripts. I tried the Perl one and it seems to work, so the problem is my Python attempts. The (working) script is:</p>
  
  <pre><code>## tool_example.pl ##
  use strict;
  use warnings;
  use LWP::UserAgent;
  
  my $base = 'http://www.uniprot.org';
  my $tool = 'mapping';
  my $params = {
    from =&gt; 'ACC', to =&gt; 'P_REFSEQ_AC', format =&gt; 'tab',
    query =&gt; 'P13368 P20806 Q9UM73 P97793 Q17192'
  };
  
  my $agent = LWP::UserAgent-&gt;new;
  push @{$agent-&gt;requests_redirectable}, 'POST';
  print STDERR "Submitting...\n";
  my $response = $agent-&gt;post("$base/$tool/", $params);
  
  while (my $wait = $response-&gt;header('Retry-After')) {
    print STDERR "Waiting ($wait)...\n";
    sleep $wait;
    print STDERR "Checking...\n";
    $response = $agent-&gt;get($response-&gt;base);
  }
  
  $response-&gt;is_success ?
    print $response-&gt;content :
    die 'Failed, got ' . $response-&gt;status_line . 
      ' for ' . $response-&gt;request-&gt;uri . "\n";
  </code></pre>
  
  <p>My questions are:</p>
  
  <p>1) How would you do that in Python?</p>
  
  <p>2) Will I be able to massively "scale" that (i.e., use a lot of entries in the query field)?</p>