Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Trying to do cl.photoupload fails #2046

Open
JojoBloxen1 opened this issue Oct 15, 2024 · 0 comments
Open

[BUG] Trying to do cl.photoupload fails #2046

JojoBloxen1 opened this issue Oct 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@JojoBloxen1
Copy link

I'm currently trying to upload a simple picture, with a caption and some extra_data. However, everytime i try, i get a 500 request error.
I've tried a ton of things, so i thought i would ask if any of y'all new anything.

image
image

These are some images of the logs i receive. My code is below:
def postmedia():
userids = str(request.args.get('userids')).replace(" ", "").split(',')
usernames = str(request.args.get('username')).replace(" ", "").split(',')
useruniqueids = str(request.args.get('useruniqueids')).replace(" ", "").split(',')
image_url = "https:" + str(request.args.get('image')) # Get the image URL instead of a base64 string
caption = str(request.args.get('title'))
captionforfile = str(request.args.get('title')).replace(" ", "_") # Caption to be used as filename
hidecomments = str(request.args.get('commentable'))
hidelikes = str(request.args.get('likes'))

if hidelikes == "False":
    hidelikes = 0
elif hidelikes == "True":
    hidelikes = 1

if hidecomments == "False":
    hidecomments = 0
elif hidecomments == "True":
    hidecomments = 1

# Create a temporary directory to save the image
with tempfile.TemporaryDirectory() as temp_dir:
    # Define the file path where the image will be saved
    image_filename = f"{captionforfile}.jpg"
    image_path = os.path.join(temp_dir, image_filename)

    # Download the image from the URL and save it as a jpg file
    response = requests.get(image_url)
    if response.status_code == 200:
        with open(image_path, "wb") as image_file:
            image_file.write(response.content)
    else:
        return "Failed to download image", 400

    # Loop through usernames and upload images
    for username, useruniqueid, userid in zip(usernames, useruniqueids, userids):
        session = load_session(username)
        cl = Client()
        cl.set_proxy(proxy)
        if session:
            cl.set_settings(session)  # Load the user's session settings
            try:
                cl.get_timeline_feed()  # Validate the session
                print(f"Sessions loaded successfully for {username}")
            except Exception as e:
                print(f"Failed to load timeline feed for {username}: {str(e)}")
        else:
            print(f"Session not found for {username}")

        # Upload the saved image file
        media = cl.photo_upload(
            path=image_path,
            caption=caption,
            extra_data={
                "like_and_view_counts_disabled": hidelikes,
                "disable_comments": hidecomments,
            }
        )
@JojoBloxen1 JojoBloxen1 added the bug Something isn't working label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant