1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] EOFError: EOF when reading a line in cpanel

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024 às 21:12.

  1. Stack

    Stack Membro Participativo

    I wrote a program in python that downloads stories of my following in instagram, but when I put this project in my host it just opens the web and when I enter the username and password it doesn't download stories and says this


    error:EOFError: EOF when reading a line ''

    in cpanel

    This is my python code:

    from flask import Flask, render_template, request, send_file
    from instagrapi import Client
    import os
    import shutil
    import zipfile

    app = Flask(__name__)

    # Ensure the download directory exists
    DOWNLOAD_DIR = "downloads"
    if not os.path.exists(DOWNLOAD_DIR):
    os.makedirs(DOWNLOAD_DIR)

    @app.route('/', methods=['GET'])
    def home():
    return render_template('index.html')
    @app.route('/download', methods=['POST'])
    def download_stories():
    username = request.form['username']
    password = request.form['password']

    cl = Client()
    cl.login(username, password)

    following_users = cl.user_following(cl.user_id)

    # Create a directory for the user stories
    user_stories_dir = os.path.join(DOWNLOAD_DIR, username)
    if not os.path.exists(user_stories_dir):
    os.makedirs(user_stories_dir)

    # Loop through each user the logged-in user is following
    for user in following_users:
    user_id = user
    user_info = cl.user_info(user_id)
    followed_username = user_info.username

    # Download stories for the current user
    stories = cl.user_stories(user_id)

    for story in stories:
    story_url = story.video_url or story.thumbnail_url
    file_extension = ".jpg" if story.thumbnail_url else ".mp4"
    filename = os.path.join(user_stories_dir, f"{followed_username}_{story.pk}{file_extension}")
    story_content = cl.story_download(story.pk)

    if isinstance(story_content, str) or isinstance(story_content, bytes):
    with open(filename, "wb") as f:
    f.write(story_content)
    elif hasattr(story_content, 'name'):
    shutil.move(story_content, filename)

    # Create a zip file of the downloaded stories
    zip_filename = os.path.join(DOWNLOAD_DIR, f"{username}_stories.zip")
    with zipfile.ZipFile(zip_filename, 'w') as zipf:
    for root, _, files in os.walk(user_stories_dir):
    for file in files:
    zipf.write(os.path.join(root, file), file)

    return send_file(zip_filename, as_attachment=True)

    @app.route('/downloads/<path:filename>', methods=['GET'])
    def download_file(filename):
    return send_file(os.path.join(DOWNLOAD_DIR, filename), as_attachment=True)

    if __name__ == '__main__':
    app.run(debug=True)

    Continue reading...

Compartilhe esta Página