urllib2 will raise an HTTPError if the credentials are incorrect and the message will be "HTTP Error 401: Unauthorized". You can use a temporary API instance to authorize the request (GetFriends (), for example) in the try / except block to determine if the credentials are valid.
import twitter, urllib2
checkCreds = twitter.Api(username, pass)
try:
checkCreds.GetFriends()
except urllib2.HTTPError, status:
if status.find('401') != -1:
print 'Invalid username/password'
Twitter , GetPublicTimeline() GetUserTimeline().