import json
import requests

def get_accounts(email, password):
    # 1: Login.
    session = requests.Session()
    data = {"username": email, "password": password, "task": "L", "nextPage": ""}
    headers = {"accept": "application/json"}
    response = session.post("https://wwws.mint.com/loginUserSubmit.xevent", data=data, headers=headers).text

    if "token" not in response:
        raise Exception("Mint.com login failed[1]")

    response = json.loads(response)
    if not response["sUser"]["token"]:
        raise Exception("Mint.com login failed[2]")

    # 2: Grab token.
    token = response["sUser"]["token"]

    # 3. Issue service request.
    request_id = "115485" # magic number? random number?
    data = {"input": json.dumps([
        {"args": {
            "types": [
                "BANK", 
                "CREDIT", 
                "INVESTMENT", 
                "LOAN", 
                "MORTGAGE", 
                "OTHER_PROPERTY", 
                "REAL_ESTATE", 
                "VEHICLE", 
                "UNCLASSIFIED"
            ]
        }, 
        "id": request_id, 
        "service": "MintAccountService", 
        "task": "getAccountsSortedByBalanceDescending"}
    ])}
    response = session.post("https://wwws.mint.com/bundledServiceController.xevent?legacy=false&token="+token, data=data, headers=headers).text
    if request_id not in response:
        raise Exception("Could not parse account data: " + response)
    response = json.loads(response)
    accounts = response["response"][request_id]["response"]
    return accounts

if __name__ == "__main__":
    import getpass, sys

    # Handle Python 3's raw_input change.
    try: input = raw_input
    except NameError: pass

    if len(sys.argv) >= 3:
        email, password = sys.argv[1:]
    else:
        email = input("Mint email: ")
        password = getpass.getpass("Password: ")

    accounts = get_accounts(email, password)
    print(json.dumps(accounts, indent=2))

@@ -105,16 +105,204 @@
 ession()
+%0A%0A    if session.get(%22https://wwws.mint.com/login.event?task=L%22).status_code != requests.codes.ok:%0A        raise Exception(%22Failed to load Mint main page '%7B%7D'%22.format(Mint.START_URL))%0A    
 %0A    dat
@@ -365,20 +365,65 @@
 %22, %22
-nextPage%22: %22
+browser%22: %22firefox%22, %22browserVersion%22: %2227%22, %22os%22: %22linux
 %22%7D%0A 
@@ -575,17 +575,16 @@
 s).text%0A
-%0A
     if %22
@@ -903,14 +903,10 @@
  = %22
-115485
+42
 %22 # 
@@ -1364,24 +1364,61 @@
 tService%22, %0A
+        #%22task%22: %22getAccountsSorted%22%0A
         %22tas
@@ -1459,16 +1459,25 @@
 cending%22
+%0A        
 %7D%0A    %5D)

integrate fixes from https://github.com/dan-v/mint-bitcoin-sync, thanks dan-v