1

I'm making a program that downloads snapchat stories. And this:

base64.b64decode(snap['media_iv']))

Is getting the error Error: Incorrect padding

The actual media_iv is: GhcakENDGbTNY6GzE1AV3w==


from __future__ import print_function

import os.path
import sys
from getpass import getpass
import base64
from pprint import pprint

from docopt import docopt
from Tkinter import *

from pysnap import get_file_extension, Snapchat

def printsnaps():
    s = Snapchat()
    s.login(u.get(), p.get())
    for snap in s.get_friend_stories():
        pprint(snap)
        path = snap["id"]
        data = s.get_story_blob(snap['media_id'],
            base64.b64decode(snap['media_key']),
            base64.b64decode(snap['media_iv']))
        if data is None:
            continue
        with (openpath, 'wb') as f:
            f.write(data)
top = Tk()
u = StringVar()
p = StringVar()
user = Entry(top, text="usermame", textvariable=u)
user.pack()
pswd = Entry(top, text="password", textvariable=p)
pswd.pack()
logb = Button(top, text="login", width = 15, command=printsnaps)
logb.pack()

top.mainloop()

SOLUTION: Tutorial was wrong, it didnt need to be decoded

2
  • possible duplicate of Decode python base64 String
    – TidB
    Jan 17, 2015 at 14:33
  • Given that GhcakENDGbTNY6GzE1AV3w== decodes fine using b64decode() as well as 'GhcakENDGbTNY6GzE1AV3w=='.decode('bas464'), how certain are you that snap['media_iv'] is set to that value? Can you show us the output of pprint(snap)?
    – mhawke
    Jan 17, 2015 at 14:44

1 Answer 1

0

Try using the string's inherited decode method:

str(snap['media_iv']).decode('base64')

I've tried decoding it, but it decodes to a bunch of binary nonsense, which shouldn't happen in the case of a SnapChat. Perhaps, your given value is incorrect.

1
  • 2
    If you try this, you will get an AttributeError thrown: 'str' object has no attribute 'decode' Nov 30, 2016 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.