def multipartRequest(cls, user, account_name, url, params={}, files={}): account = Account.gql( "WHERE service = :1 and account_name = :2 and user_ref = :3", cls.service, account_name, user.key()).get() if account == None or account.access_token == None: raise Exception('Access token is not saved. : service = %s, account_name = %s' % (cls.service, account_name) ) BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$' body = utils.multipart_encode(params, files, BOUNDARY) headers = { 'Content-Type': 'multipart/form-data; boundary=%s' % BOUNDARY } token = oauth.Token(account.access_token, account.secret) client = cls.newOAuthClient(token) return client.request(url, "POST", body, headers)
def call_multipart(user, account_name, url, params={}, files={}): account = Account.gql( "WHERE service = :1 and account_name = :2 and user_ref = :3", "facebook", account_name, user.key()).get() if account == None or account.access_token == None: raise Exception('Access token is not saved. : service = facebook, account_name = %s' % (account_name) ) params["access_token"] = account.access_token BOUNDARY = u'----------ThIs_Is_tHe_bouNdaRY_$' body = utils.multipart_encode(params, files, BOUNDARY) headers = { 'Content-Type': 'multipart/form-data; boundary=%s' % BOUNDARY } response = urlfetch.fetch(url, method=urlfetch.POST, payload=body, headers=headers, deadline=10) return response
def call_multipart(user, account_name, url, params={}, files={}): account = Account.gql( "WHERE service = :1 and account_name = :2 and user_ref = :3", "facebook", account_name, user.key()).get() if account == None or account.access_token == None: raise Exception( 'Access token is not saved. : service = facebook, account_name = %s' % (account_name)) params["access_token"] = account.access_token BOUNDARY = u'----------ThIs_Is_tHe_bouNdaRY_$' body = utils.multipart_encode(params, files, BOUNDARY) headers = {'Content-Type': 'multipart/form-data; boundary=%s' % BOUNDARY} response = urlfetch.fetch(url, method=urlfetch.POST, payload=body, headers=headers, deadline=10) return response