I am trying to use adwords api python scripts from hapi.js using python-shell. Now when i write a simple main() function with or without arguments i get the output properly on my screen but when i use the api code i get an error but i still get the error.
controller.js
var PythonShell = require('python-shell');
PythonShell.defaultOptions = { scriptPath: './server/python/' };
exports.adwords = {
handler: function(request, reply){
PythonShell.run('script.py', function (err, res) {
if (err) throw err;
reply(res);
});
});
script.py
import logging
import os
import sys, json
import csv
from googleads import adwords
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
def main(client):
#-----sample code-----
file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),"report.csv")
f = open(file_path,'wb')
f.write('Bacon is not a vegetable')
f.close()
if __name__ == '__main__':
adwords_client = adwords.AdWordsClient.LoadFromStorage()
adwords_client.SetClientCustomerId('111-111-1111')
main(adwords_client)
My guess is python-shell is not able to handle streaming of data so it considers the first line of the output as error and returns. Also api processing happens with some async code.
I am trying to use adwords api python scripts from hapi.js using python-shell. Now when i write a simple main() function with or without arguments i get the output properly on my screen but when i use the api code i get an error but i still get the error.
controller.js
script.py
Error which i get:
My guess is python-shell is not able to handle streaming of data so it considers the first line of the output as error and returns. Also api processing happens with some async code.