[BUG] Trying to do cl.photoupload fails
Opened this issue · 0 comments
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.
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,
}
)