Python-Twitter script works at home and not at University. Deadline REALLY soon
Question: I've written quite a simple python script that pulls in tweets and turns on a
GPIO if a filter is matched. I've tried it at home and it works really well,
however, on the University network it seems not to be able to connect to
twitter.

The details of the University network are WIRELESS SSID: Uni-WiFi WPA2
Enterprise

It uses PEAP (MSCHAPv2) to connect, meaning that I need to type in my
university username and password. The network is connected at present and I
can browse the internet, but when I launch the python script I get the error:

    
    
    urllib2.HTTPError: HTTP Error 401: Unauthorized
    

Here is the full python script - If any body could help it would be amazing,
this needs handing in really soon!

    
    
    #!/usr/bin/env python
    
    import twitter
    import RPi.GPIO as GPIO ## Import GPIO library
    import time ## Import 'time' library. Allows us to use 'sleep'
    from termcolor import colored
    
    GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
    GPIO.cleanup()
    
    #My app keys and secrets
    CONSUMER_KEY = 'TXXGPRg'
    CONSUMER_SECRET = 'jRVxtEgf1CQWuan0N8L4a3s'
    OAUTH_TOKEN = '528854Jaudhna2K36g4y79oiwUq'
    OAUTH_SECRET = 'ZoQEv1deAQ'
    
    FILTER_TAG = u'art'  # Can also be just text, like u'idol', but expect a lot more results!
    
    # We want a continuous stream of events which match a given tag, so we need to use the streaming API.
    twitter_stream = twitter.TwitterStream(auth=twitter.OAuth(OAUTH_TOKEN,OAUTH_SECRET,CONSUMER_KEY,CONSUMER_SECRET))
    
    # Now, we don't want every single tweet from the stream, so we'll filter to include only specific text, or a specific tag.
    iterator = twitter_stream.statuses.filter(track = FILTER_TAG)
    
    # Now, iterator is a generator which yields a new tweet whenever it sees one. We need to loop over it forever.
    for tweet in iterator:
    
            print colored(tweet.get(u'user', {}).get(u'name'), 'white', 'on_red'), colored(tweet.get(u'text'), 'cyan')
    
            if "hate" in tweet.get(u'text', u'fake_text_that_never_matches'):  # Now, you need to light up the light for 5 seconds, then shut it off.
                print colored("Switch turned ON!", "red", 'on_yellow')
                GPIO.setup(7, GPIO.OUT)
                GPIO.output(7,True)## Switch on pin 7
                time.sleep(5)## Wait
                GPIO.output(7,False)## Switch off pin 7
    
            print "----------------------------------------------------------------------------------------------------------------------------------------------------"
    


Answer: Part of the OAuth signature is a timestamp, which is generated when you make
the request. If your server's time differs too much from Twitter's server
time, the Twitter server will reject your request with a 401. So, check the
time being returned by the Twitter server and make sure your local machine
that is generating the signature matches the same time.

