try to login again if server sends 403
This commit is contained in:
parent
df874cd202
commit
16ce1c8aa1
1 changed files with 26 additions and 13 deletions
|
@ -58,14 +58,7 @@ class Client(object):
|
||||||
else:
|
else:
|
||||||
self._config = config
|
self._config = config
|
||||||
self.api = API(self._config['url'], media_cache=self.media_cache())
|
self.api = API(self._config['url'], media_cache=self.media_cache())
|
||||||
|
self.signin()
|
||||||
if 'username' in self._config:
|
|
||||||
r = self.api.signin(username=self._config['username'], password=self._config['password'])
|
|
||||||
if r['status']['code'] == 200 and not 'errors' in r['data']:
|
|
||||||
self.user = r['data']['user']
|
|
||||||
else:
|
|
||||||
self.user = False
|
|
||||||
print 'login failed'
|
|
||||||
|
|
||||||
conn, c = self._conn()
|
conn, c = self._conn()
|
||||||
|
|
||||||
|
@ -122,6 +115,17 @@ class Client(object):
|
||||||
return json.loads(row[2])
|
return json.loads(row[2])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def signin(self):
|
||||||
|
if 'username' in self._config:
|
||||||
|
r = self.api.signin(username=self._config['username'], password=self._config['password'])
|
||||||
|
if r['status']['code'] == 200 and not 'errors' in r['data']:
|
||||||
|
self.user = r['data']['user']
|
||||||
|
else:
|
||||||
|
self.user = False
|
||||||
|
print 'login failed'
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def scan_file(self, path):
|
def scan_file(self, path):
|
||||||
conn, c = self._conn()
|
conn, c = self._conn()
|
||||||
|
|
||||||
|
@ -282,8 +286,12 @@ class Client(object):
|
||||||
if oshash in filenames:
|
if oshash in filenames:
|
||||||
filename = filenames[oshash]
|
filename = filenames[oshash]
|
||||||
info = files['info'][oshash]
|
info = files['info'][oshash]
|
||||||
self.api.uploadVideo(os.path.join(prefix, filename),
|
if not self.api.uploadVideo(os.path.join(prefix, filename),
|
||||||
data, profile, info)
|
data, profile, info):
|
||||||
|
if not self.signin():
|
||||||
|
print "failed to login again"
|
||||||
|
return
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print oshash, "missing"
|
print oshash, "missing"
|
||||||
else:
|
else:
|
||||||
|
@ -423,9 +431,14 @@ class API(object):
|
||||||
#upload video in chunks
|
#upload video in chunks
|
||||||
url = self.url + 'upload/' + '?profile=' + str(profile) + '&oshash=' + i['oshash']
|
url = self.url + 'upload/' + '?profile=' + str(profile) + '&oshash=' + i['oshash']
|
||||||
ogg = Firefogg(cj=self._cj, debug=True)
|
ogg = Firefogg(cj=self._cj, debug=True)
|
||||||
ogg.upload(url, i['video'], data)
|
if not ogg.upload(url, i['video'], data):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print "done"
|
print "failed"
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
if DEBUG:
|
||||||
|
print "done"
|
||||||
|
return True
|
||||||
|
|
||||||
def uploadData(self, filename, oshash):
|
def uploadData(self, filename, oshash):
|
||||||
form = ox.MultiPartForm()
|
form = ox.MultiPartForm()
|
||||||
|
|
Loading…
Reference in a new issue