requests - Gateway Timeout
<p>this is a test script to request data from <code>Rovi API</code>, provided by the <code>API</code> itself.</p>

<p><strong>test.py</strong></p>

<pre><code>import requests 
import time
import hashlib
import urllib

class AllMusicGuide(object):
    api_url = 'http://api.rovicorp.com/data/v1.1/descriptor/musicmoods'

    key = 'my key'
    secret = 'secret'

    def _sig(self):
        timestamp = int(time.time())

        m = hashlib.md5()
        m.update(self.key)
        m.update(self.secret)
        m.update(str(timestamp))

        return m.hexdigest()

    def get(self, resource, params=None):
        """Take a dict of params, and return what we get from the api"""

        if not params:
            params = {}

        params = urllib.urlencode(params)

        sig = self._sig()

        url = "%s/%s?apikey=%s&amp;sig=%s&amp;%s" % (self.api_url, resource, self.key, sig, params)

        resp = requests.get(url)

        if resp.status_code != 200:         
            # THROW APPROPRIATE ERROR
                print ('unknown err')

        return resp.content
</code></pre>

<p>from another <code>script</code> I import the <code>module</code>:</p>

<pre><code>from roviclient.test import AllMusicGuide
</code></pre>

<p>and create an instance of the <code>class</code> inside a <code>mood function</code>:</p>

<pre><code>def mood():
    test = AllMusicGuide()
    print (test.get('[moodids=moodids]'))
</code></pre>

<p>according to <a href="http://developer.rovicorp.com/docs" rel="nofollow">documentation</a>, the following is the <code>syntax</code> for requests:</p>

<pre><code>descriptor/musicmoods?apikey=apikey&amp;sig=sigâ[&amp;moodids=moodids]â[&amp;format=format]â[&amp;country=country]â[&amp;language=language]
</code></pre>

<p>but running the script I get the following error:</p>

<p><code>unknown err
&lt;h1&gt;Gateway Timeout&lt;/h1&gt;:</code></p>

<p>what is wrong?</p>

<p>"504, try once more. 502, it went through."</p>

<p>Your code is fine, this is a network issue. "Gateway Timeout" is a 504. The intermediate host handling your request was unable to complete it. It made its own request to another server on your behalf in order to handle yours, but this request took too long and timed out. Usually this is because of network congestion in the backend; if you try a few more times, does it sometimes work?</p>

<p>In any case, I would talk to your network administrator. There could be any number of reasons for this and they should be able to help fix it for you.</p>

python api python-requests