Hey everyone,
I’ve been working on a Python-based download tracker for my website, <a
href="https://waplusorignal.com" target="_blank">www.Waplusorignal.com</a>
, where I provide WhatsApp Plus APK downloads. The goal is to track user
interactions with the download buttons, like which APK versions are being
downloaded most often. However, I’ve run into a few issues that I could really
use some help with.
Issue 1: Flask API Not Updating Logs
I'm using Flask to create an API that tracks the downloads. The problem is that
sometimes the API doesn’t update the download logs, even though the users are
definitely interacting with the buttons. Here’s a snippet of the code that
handles the logging:
python
@app.route('/download/<apk_version>')
def download(apk_version):
try:
# Log download in the database
log_download(apk_version)
return send_file(f'/path/to/apks/{apk_version}.apk', as_attachment=True)
except Exception as e:
print(f"Error: {e}")
return "Download failed", 500
Sometimes it logs correctly, but at other times it seems to miss the download
request. Could this be due to concurrent requests or am I handling the logging
in the wrong place?
Issue 2: SQLite Database Lock
I’m using SQLite for storing the logs, but I keep getting an error about the
database being locked when there are multiple requests at the same time. The
error looks something like this:
csharp
Copy code
sqlite3.OperationalError: database is locked
I know that SQLite has some concurrency limitations, but I’m not sure how to
work around them for this project. Should I switch to a different database for
better handling multiple requests, or is there a Python-based solution to avoid
this issue?
Issue 3: File Not Found Errors
Some users report that they get a "file not found" error when trying to
download APKs, even though the files are present on the server. I think it
might have to do with how the file paths are being handled, but I can’t seem to
pinpoint the exact cause.
Here’s the file download code I’m using:
python
Copy code
def log_download(apk_version):
conn = sqlite3.connect('downloads.db')
cursor = conn.cursor()
cursor.execute('INSERT INTO downloads (apk_version, timestamp) VALUES (?,
?)', (apk_version, datetime.now()))
conn.commit()
conn.close()
Any suggestions on how to make this more reliable, especially when handling
multiple downloads at once?
Conclusion:
I'm stuck with these issues and would greatly appreciate any insights from the
community. Has anyone else faced similar problems with Python/Flask or SQLite
when dealing with multiple requests? If so, how did you solve them? i did it on
my 2nd site <a href="https://apktopfollows.org/"
target="_blank">apktopfollows.org</a>
Thanks in advance!
_______________________________________________
Isbg mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/isbg.python.org/
Member address: [email protected]