Search code examples
pythontelethon

RPCError 400: STICKER_MIME_INVALID (caused by UploadProfilePhotoRequest)


When attempting to upload a profile photo, an RPCError 400: STICKER_MIME_INVALID (caused by UploadProfilePhotoRequest) error is displayed.

Code:

async def to_add_profile_photo( photo_dir ,session_file):
async with TC(session_file) as client:
    photos = [os.path.join(photo_dir, f) for f in os.listdir(photo_dir) if os.path.isfile(os.path.join(photo_dir, f))]
    if not photos:
        print(f'Error: No files in {photo_dir}')
        return
    photo_path = random.choice(photos)
    try:
        with open(photo_path, 'rb') as f:
            result = await client(UploadProfilePhotoRequest(await client.upload_file(f)))
        if result:
            print('OK')
    except Exception as e:
        print(f'Error during upload: {e}')

The file address dictionary is formed correctly and the random file is also transmitted correctly. The error occurs during the UploadProfilePhotoRequest stage. I have tried different formats: jpeg, png, made square photos 512512, 640640 etc, round photos, but the result is the same - an error.


Solution

  • Updates add new features by layers, so, order of parameters can change if necessary, or new required arguments can appear, using keyword arguments is better mostly for Raw requests to avoid the former.

    Current first positional arg is "fallback" (see TL), so, you need to pass it to file instead of that:

    UploadProfilePhotoRequest(file=await client.upload_file(f))