Skip to content

Commit

Permalink
Adding TokenExpired Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Silas committed Jun 2, 2011
1 parent f379420 commit 5263a58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pytube/client.py
Expand Up @@ -224,7 +224,15 @@ def _gdata_request(self, url, query=None, data=None, headers=None, timeout=None)
headers['X-GData-Key'] = 'key=' + self.dev_key

request = urllib2.Request(url, data, headers)
return urllib2.urlopen(request, timeout=timeout)
try:
return urllib2.urlopen(request, timeout=timeout)
except urllib2.HTTPError, e:
if e.getcode() == 401:
e.reponse = e.read()
if 'TokenExpired' in e.response:
raise pytube.exceptions.TokenExpired()
raise e
raise

def _gdata_json(self, url, query=None, data=None, headers=None):
query = query or {}
Expand Down
4 changes: 4 additions & 0 deletions pytube/exceptions.py
Expand Up @@ -11,6 +11,10 @@ def __init__(self, data):
self.solved = None


class TokenExpired(AuthenticationError):
""" You are using an expired authentication token """


class VideoException(Exception):
""" Failed to access a video """

Expand Down

0 comments on commit 5263a58

Please sign in to comment.