Pulling token from JSON responce in Python -
i learning python , working api mediafire , trying automate simple processes. running bit of confusion after pass post session token. problem not sure how extract token response. here call session token:
import hashlib import time import urllib.request token = hashlib.sha1() token.update("calvinrock0406@gmail.comheaven3610255k592k2di4u9uok3e8u9pkfepjfoc809kfutv5z".encode('utf-8')) token_dig = token.hexdigest() urllib.request.urlopen("https://www.mediafire.com/api/user/get_session_token.php?application_id=36102&signature=" + token_dig + "&email=calvinrock0406@gmail.com&password=heaven&token_version=2&response_format=json") response: html = response.read()
and here responce call:
b'{"response":{"action":"user\\/get_session_token","session_token":"618679cd5046c48fface93dee366a1a07eacfefc5bce88173d5118bb3f128f539602dc54f6d667825a376bc2f86b41a5b1cbe178cd45dfcb4ddfc8e9652f7c529db233181655ec42","secret_key":"774329384","time":"1454700043.4884","ekey":"a84adbba31f9ae8ef717486616a97c63","pkey":"b4dfdc307d","result":"success","current_api_version":"1.5"}}'
any noob appreciated
i recommend using requests
instead of urllib
, , use json()
work response:
import json import hashlib import requests token = hashlib.sha1() token.update("calvinrock0406@gmail.comheaven3610255k592k2di4u9uok3e8u9pkfepjfoc809kfutv5z".encode('utf-8')) token_dig = token.hexdigest() response = requests.get("https://www.mediafire.com/api/user/get_session_token.php?application_id=36102&signature=" + token_dig + "&email=calvinrock0406@gmail.com&password=heaven&token_version=2&response_format=json") json_response = response.json() print json_response["response"]["session_token"]
Comments
Post a Comment