Geting error using python 3.5 : a_token = r.json() mention below

Akbar Shaikh akbar at games2win.com
Tue Dec 20 07:28:19 EST 2016


import io
import csv
import glob
import os.path
import requests
import subprocess
import urllib.request
import json
import time
import xlwt
import xlrd
import datetime
from datetime import date, timedelta

def main():
        """ Run the whole toolchain for all accounts. """
        _clean()

        payload = {'client_id':'xxxx' ,
                    'client_secret':'xxxx',
                    'grant_type':'client_credentials'}
        headers1 = {
                'Content-Type':'application/json'
                }
        
        r = requests.post('https://auth.smaato.com/v2/auth/token/ HTTP/1.1',params=payload,auth=('username', 'password'),headers = headers1,)

        a_token = r.json()
        
        ACCESSTOKEN = a_token['access_token']
        print ('Bearer ' + ACCESSTOKEN)

        content2 = {
                    'client_id':'xxxx' ,
                    'client_secret':'xxxx',
                    'grant_type':'client_credentials',
                    'Authorization': 'Bearer' + ACCESSTOKEN,
                    'POST':'https://api.smaato.com/v1/reporting/ HTTP/1.1',
                    'Content-Type':'application/json',
                    'Host': 'api.smaato.com',
                    'criteria':{"dimension":"ApplicationId","child":"null"},
                    'kpi': {"clicks : true"},
                    'period':{"period_type":"fixed","start_date":"2016-12-7","end_date":"2016-12-7"}
                    }
        
        headers2 = {
                'client_id':'xxxx' ,
                'client_secret':'xxxx',
                'grant_type':'client_credentials',
                'Authorization': 'Bearer' + ACCESSTOKEN,
                'Username':'Username',
                'Password':'Password',
                'Content-Type': 'application/json',
                'Host': 'api.smaato.com',
                }
        s = requests.post('https://api.smaato.com/v1/reporting/',params=content2,auth=('username', 'password'), headers = headers2)
        print(s.content)
              
def _clean():
        """ Cleans old data files.
        """
        for f in glob.glob('./Numbers *.csv'):
                os.remove(f)
                
if '__main__' == __name__:
        main()
-------------------------------------------------------------------------
Error:  Traceback (most recent call last):
  File "C:\Users\xxxx\Desktop\Smaato Akbar.py", line 66, in <module>
    main()
  File "C:\Users\xxxx\Desktop\Smaato Akbar.py", line 28, in main
    a_token = r.json()
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\models.py", line 850, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Users\xxxx\AppData\Local\Programs\Python\Python35-32\lib\site-packages\simplejson\__init__.py", line 516, in loads
    return _default_decoder.decode(s)
  File "C:\Users\xxxx\AppData\Local\Programs\Python\Python35-32\lib\site-packages\simplejson\decoder.py", line 374, in decode
    obj, end = self.raw_decode(s)
  File "C:\Users\xxxx\AppData\Local\Programs\Python\Python35-32\lib\site-packages\simplejson\decoder.py", line 404, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char 0)



More information about the Python-list mailing list