blocking api redirect with requests in python 3.4
Question: I am creating a python program that uses an online thesaurus and returns
synonyms. Unfortunately sometimes it will take a word that is spelled wrong,
and redirect to a page for a word that is close to it, which is sometimes
problematic. How can I stop it from redirecting? I would appreciate any
advice. This is the code that applies:

    
    
    def get_synonym(the_word):
        #return a dictionary of the thesaurus results of the word
        theurl = (the api key for the thesaurus)
        new_word = the_word + "/json"
        theurl = theurl + new_word
        r = requests.get(theurl)    
        thewords = r.text   #all the text for the results
        from json import loads
        thewords = json.loads(thewords) #make a dictionary of terms
        return thewords #return dictionary of synonyms for the_word
    


Answer: Use the [`allow_redirects=False`](http://docs.python-
requests.org/en/latest/user/quickstart/#redirection-and-history) keyword
argument:

    
    
    r = requests.get(url, allow_redirects=False)
    

By default, requests follows redirects on all methods except `HEAD`.

