Function returning false when it should be returning True. Encoding issue?
<p>I am currently working on a validation function that returns <code>True</code> or <code>False</code> based on an expression (if statement). The header is base64 decoded and then <code>json.loads</code> is used to convert it into a dict. Here is the method:</p>

<pre><code>    @staticmethod
    def verify(rel):
        if not('hello' in rel and rel['hello'] is 'blah' and 'alg' in rel and rel['alg'] is 'HS256'):
            return False
        return True
</code></pre>

<p>The check only fails if the parameter was base 64 decoded and converted to a dict. Why? Any help would be appreciated.</p>

<p>Edit: As per request, here Is how I call the method. Python 3.5.2</p>

<pre><code>p = {'hello': 'blah', 'alg': 'HS256'}
f = urlsafe_b64encode(json.dumps(p).encode('utf-8'))
h = json.loads(str(urlsafe_b64decode(f))[2:-1], 'utf-8')
print(verify(h))
</code></pre>

<p>The issue here is your use of the <code>is</code> operator to check the equality of the strings. The <code>is</code> operator checks if its two arguments refer to the same object, which is not the behavior you want here. To check if the strings are equal, use the equality operator:</p>

<pre><code> def verify(rel):
    if not('hello' in rel and rel['hello'] == 'blah' and 'alg' in rel and rel['alg'] == 'HS256'):
        return False
    return True
</code></pre>

python json base64