The code below, it shows the download url in the response but if I try to download from the Download button, it has {"error_code":31326,"error_msg":"user is not authorized, hitcode:109","request_id":347419335550786427}
. But, If I copy the same download URL and paste on a browser URL , it gets downloaded.
Code:
`@app.route(‘/convert’, methods=[‘POST’])
def convert():
try:
app.logger.debug(“Received form data: %s”, request.form)
# Load cookies and headers from the file
cookies, headers = load_cookies_and_headers()
# Get the initial URL from the form data
url1 = request.form['terabox_url']
app.logger.debug(f"Initial URL: {url1}")
# Use a new requests session for making HTTP requests
with requests.Session() as session:
# Follow redirects manually to get the final URL
response1 = session.get(url1, cookies=cookies, headers=headers, allow_redirects=False)
while response1.is_redirect:
url1 = response1.headers['Location']
app.logger.debug(f"Redirected to URL: {url1}")
response1 = session.get(url1, cookies=cookies, headers=headers, allow_redirects=False)
response1.raise_for_status()
app.logger.debug(f"Response 1 status code: {response1.status_code}")
jsToken = extract_js_token(response1.text)
app.logger.debug(f"Extracted jsToken: {jsToken}")
if jsToken:
parsed_url = urllib.parse.urlparse(url1)
query_params = urllib.parse.parse_qs(parsed_url.query)
surl = query_params.get('surl', [None])[0]
app.logger.debug(f"Extracted surl: {surl}")
if surl:
url2 = f'https://www.1024tera.com/share/list?app_id=&web=1&channel=dubox&clienttype=0&jsToken={jsToken}&dp-logid=&page=1&num=20&by=name&order=asc&site_referer=&shorturl={surl}&root=1'
response2 = session.get(url2, headers=headers, cookies=cookies)
response2.raise_for_status()
app.logger.debug(f"Response 2 status code: {response2.status_code}")
json_response = response2.json()
app.logger.debug(f"JSON response: {json.dumps(json_response, indent=4)}")
if json_response and json_response.get('errno') == 0:
list_item = json_response['list'][0]
download_url = list_item['dlink']
streaming_url = f'https://www.1024tera.com/share/streaming?uk={json_response["uk"]}&shareid={json_response["share_id"]}&type=M3U8_FLV_264_480&fid={list_item["fs_id"]}&sign={list_item["md5"]}×tamp={json_response["server_time"]}&esl=1&isplayer=1&ehps=1&clienttype=0&app_id=250528&web=1&channel=dubox'
thumbnail_url = list_item['thumbs']['url3']
server_filename = list_item['server_filename']
human_readable_size = convert_size(int(list_item['size']))
return jsonify({
'download_url': download_url,
'streaming_url': streaming_url,
'thumbnail_url': thumbnail_url,
'server_filename': server_filename,
'human_readable_size': human_readable_size
})
else:
app.logger.error("Error in JSON response: {}".format(json_response.get('errmsg', 'Unknown error')))
return jsonify({'error': 'Invalid JSON response from server.'}), 400
else:
app.logger.error("Failed to extract surl.")
return jsonify({'error': 'Failed to extract surl.'}), 400
else:
app.logger.error("Failed to extract jsToken.")
return jsonify({'error': 'Failed to extract jsToken.'}), 400
except Exception as e:
app.logger.exception("Exception occurred")
return jsonify({'error': str(e)}), 500`
I have tried using flask session, but for small size files, it gets downloaded but for bigger size files, it takes much time to load the download , also the file is not downloaded, instead it gets downloaded as download.htm but autoblocked too.
test services is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.