Fix Lychee upload
parent
d84507bb43
commit
0c4f8d97f2
|
@ -73,20 +73,22 @@ def save_img(path, img, img_format):
|
||||||
return filepath
|
return filepath
|
||||||
|
|
||||||
def login():
|
def login():
|
||||||
auth = {'user': SCREENSHOT_CONFIG['user'], 'password': SCREENSHOT_CONFIG['password']}
|
data = {'username': SCREENSHOT_CONFIG['user'], 'password': SCREENSHOT_CONFIG['password'], 'function': 'Session::login'}
|
||||||
|
|
||||||
# Get initial cookies
|
# Get initial cookies
|
||||||
s = requests.Session()
|
s = requests.Session()
|
||||||
r = s.get(SCREENSHOT_CONFIG['base_url'])
|
r = s.post(SCREENSHOT_CONFIG['base_url'] + '/api/Session::init')
|
||||||
|
|
||||||
# Set the CSRF token for the whole session
|
# Set the CSRF token for the whole session
|
||||||
# Also replace the ending %3D (=), they stop header from being valid (why ?)
|
# Also replace base64 padding
|
||||||
s.headers.update({'X-XSRF-TOKEN': r.cookies['XSRF-TOKEN'].replace('%3D', '')})
|
s.headers.update({
|
||||||
|
'X-XSRF-TOKEN': r.cookies['XSRF-TOKEN'].replace('%3D', '')
|
||||||
|
})
|
||||||
|
|
||||||
r = s.post(SCREENSHOT_CONFIG['base_url'] + '/api/Session::login', data=auth)
|
r = s.post(SCREENSHOT_CONFIG['base_url'] + '/api/Session::login', data=data)
|
||||||
|
|
||||||
if r.status_code != 200:
|
if 'false' in r.text:
|
||||||
raise RuntimeError("Cannot login to Lychee!")
|
raise RuntimeError(f"Cannot login to Lychee! [{r.status_code}] {r.text}")
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
@ -116,7 +118,7 @@ def upload_image(session, album_id, binary_img, img_format):
|
||||||
dump = session.prepare_request(r)
|
dump = session.prepare_request(r)
|
||||||
r = session.post(SCREENSHOT_CONFIG['base_url'] + '/api/Photo::add', data=data, files=files)
|
r = session.post(SCREENSHOT_CONFIG['base_url'] + '/api/Photo::add', data=data, files=files)
|
||||||
print(r.text)
|
print(r.text)
|
||||||
if "Error" in r.text:
|
if "false" in r.text:
|
||||||
raise RuntimeError("Unknown error while uploading picture")
|
raise RuntimeError("Unknown error while uploading picture")
|
||||||
|
|
||||||
return r.text
|
return r.text
|
||||||
|
|
Loading…
Reference in New Issue