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

  • possible duplicate of [Decode python base64 String](http://stackoverflow.com/questions/11656115/decode-python-base64-string) – TidB Jan 17 '15 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 '15 at 14:44

1 Answers1

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.

Malik Brahimi
  • 16,341
  • 7
  • 39
  • 70