Digital Developer Conference: a FREE half-day online conference focused on AI & Cloud – North America: Nov 2 – India: Nov 9 – Europe: Nov 14 – Asia Nov 23 Register now

Close outline
  • United States
IBM?
  • Site map
IBM?
  • Marketplace

  • Close
    Search
  • Sign in
    • Sign in
    • Register
  • IBM Navigation
IBM Developer Answers
  • Spaces
    • Blockchain
    • IBM Cloud platform
    • Internet of Things
    • Predictive Analytics
    • Watson
    • See all spaces
  • Tags
  • Users
  • Badges
  • FAQ
  • Help
Close

Name

Community

  • Learn
  • Develop
  • Connect

Discover IBM

  • ConnectMarketplace
  • Products
  • Services
  • Industries
  • Careers
  • Partners
  • Support
10.190.13.195

Refine your search by using the following advanced search options.

Criteria Usage
Questions with keyword1 or keyword2 keyword1 keyword2
Questions with a mandatory word, e.g. keyword2 keyword1 +keyword2
Questions excluding a word, e.g. keyword2 keyword1 -keyword2
Questions with keyword(s) and a specific tag keyword1 [tag1]
Questions with keyword(s) and either of two or more specific tags keyword1 [tag1] [tag2]
To search for all posts by a user or all posts with a specific tag, start typing and choose from the suggestion list. Do not use a plus or minus sign with a tag, e.g., +[tag1].
  • Ask a question

Running python script in IBM Watson node.js chatbot

50QWUB35AT gravatar image
Question by Vaibhav Kapur  (1) | Apr 28, 2018 at 03:53 AM watsonpythonnode.jsconversationassistantnode-sdk

I made a chatbot in Node.js with IBM Watson. I'm trying to run a python script in it but I'm not able to. I tried browserify and bundled up all dependencies in a .js file and called the script in the html page but still it isn't working.

var PythonShell = require('python-shell');

var options = { mode: 'text', args: 765 };

 PythonShell.run('pyt.py', options, function (err, results) {
     if (err) throw err;
     console.log('results: %j', results[0].toString());
 });

It's running on locally between a node.js and a python file. But, doesn't work when I deploy the chatbot on a server.

People who like this

  0
Comment
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster

1 reply

  • Sort: 
110000PNBC gravatar image

Answer by @chughts (12979) | Apr 28, 2018 at 04:20 AM

Standard issues when you see 'it is running locally but doesn't work when I deploy to a server'. There will be a discrepancy between the two runtimes.

  1. Make sure that you have included all dependencies in your package.json file.

  2. Make sure that you specify a node.js version in your package.json file.

  3. If the default set of node.js build packs do not support your version of node, then force to an older build pack by specifying it in your manifest.yml file.

  4. If it still doesn't work, then force version dependencies by running npm module npm-shrinkwrap

  5. Learn to search the forum for similar questions, as this issue has been answered several times across multiple forums, over many years.

Comment
Vaibhav Kapur

People who like this

  1   Show 5   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
50QWUB35AT gravatar image Vaibhav Kapur (1)   Apr 28, 2018 at 05:33 AM 0
Share

I'm running it on the localhost:3000 for now. The issue is not about deployment. It's about being able to transfer data from node.js to python on a server or not.

As I mentioned, I'm able to transfer data from node to python locally(as in running node filename.js in cmd). But, the python-shell/any require method does not seem to work when deployed on a server.

I've tried browserify. I've even mentioned it in package.json.

50QWUB35AT gravatar image Vaibhav Kapur (1)   Apr 28, 2018 at 05:37 AM 0
Share

And this node.js file is an IBM Watson conversation(chatbot) file mind you. I was just wondering if there is any restriction from Watson's end. For browserify, I've mentioned the bundle.js file name in script tag in the index.html(The main chatbot page).

110000PNBC gravatar image @chughts (12979) ♦   Apr 28, 2018 at 07:15 AM 0
Share

I see. In that case the question relates to the path of the file pyt.py. In node.js you should use __dirname to help locate the direction of the path. Get __dirname to work locally, before deploying to the cloud.

50QWUB35AT gravatar image Vaibhav Kapur (1) @chughts (12979) ♦   Apr 29, 2018 at 07:12 AM 0
Share

Can't seem to display __dirname in the chatbot. If I'm running the chatbot in the http://localhost:3000/ and in the local folder my file is in public/js folder, would the directory name be http://localhost:3000/public/js ?

110000PNBC gravatar image @chughts (12979) ♦   Apr 30, 2018 at 06:29 PM 0
Share

Yes, but everything that you put in the public directory is accessible by anyone over http. So if its a file that shouldn't be accessible by http then it shouldn't be in public. So if its in the directory scripts

Normally you use _dirname with path, eg.

 path.join(__dirname, '/scripts')

so the directory would be ./scripts when running in localhost.

Follow this question

154 people are following this question.

Answers

Answers & comments

Related questions

Can't use require method in Watson node.js chatbot 0 Answers

Calling more than one Watson API 2 Answers

Watson Assistant: Updating the response to user dynamically 2 Answers

Check if user input isn't in the context array 1 Answer

With the iOS Watson Assistant framework, how do you create the 'Context' object in Swift using the response JSON object? 0 Answers

  • Contact
  • Privacy
  • IBM Developer Terms of use
  • Accessibility
  • Report Abuse
  • Cookie Preferences

Powered by AnswerHub

Authentication check. Please ignore.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • API Connect
  • Analytic Hybrid Cloud Core
  • Application Performance Management
  • Appsecdev
  • BPM
  • Blockchain
  • Business Transaction Intelligence
  • CAPI
  • CAPI SNAP
  • CICS
  • Cloud Analytics
  • Cloud Automation
  • Cloud Object Storage
  • Cloud marketplace
  • Collaboration
  • Content Services (ECM)
  • Continuous Testing
  • Courses
  • Customer Experience Analytics
  • DB2 LUW
  • Data and AI
  • DataPower
  • Decision Optimization
  • DevOps Build
  • DevOps Services
  • Developers IBM MX
  • Digital Commerce
  • Digital Experience
  • Finance
  • Global Entrepreneur Program
  • Hadoop
  • Hybrid Cloud Core
  • Hyper Protect
  • IBM Cloud platform
  • IBM Design
  • IBM Forms Experience Builder
  • IBM Maximo Developer
  • IBM StoredIQ
  • IBM StoredIQ-Cartridges
  • IIDR
  • ITOA
  • InformationServer
  • Integration Bus
  • Internet of Things
  • Kenexa
  • Linux on Power
  • LinuxONE
  • MDM
  • Mainframe
  • Messaging
  • Node.js
  • ODM
  • Open
  • PartnerWorld Developer Support
  • PowerAI
  • PowerVC
  • Predictive Analytics
  • Product Insights
  • PureData for Analytics
  • Push
  • QRadar App Development
  • Run Book Automation
  • Search Insights
  • Security Core
  • Storage
  • Storage Core
  • Streamsdev
  • Supply Chain Business Network
  • Supply Chain Insights
  • Swift
  • UBX Capture
  • Universal Behavior Exchange
  • UrbanCode
  • WASdev
  • WSRR
  • Watson
  • Watson Campaign Automation
  • Watson Content Hub
  • Watson Marketing Insights
  • dW Answers Help
  • dW Premium
  • developerWorks Sandbox
  • developerWorks Team
  • Watson Health
  • More
  • Tags
  • Questions
  • Users
  • Badges