Make http call from node to python in heroku dyno

时光毁灭记忆、已成空白 提交于 2020-01-15 10:14:42

问题


I've inherited a repository that contains both a NodeJS part and a Python part. The project structure is such that the NodeJS is at the root of the repository, and the Python pieces are in a Python folder:

root
|- app
  |- some.js
  |- files.js
|- Python
  |- other.py
  |- files.py

I've set up a Heroku dyno to serve both a Python server and a NodeJS server, by doing this in my Procfile (based loosely on this older article):

web: npm start
python: sh -c 'cd ./Python/ && export PYTHONPATH=. && python other.py'

The python project is set up to use port 2001. It's a Bottle application and on starting the server I pass in this port (taken from the Heroku settings).

In my logging, I can see that both are started successfully. Simplified:

Bottle v0.12.13 server starting up (using WaitressServer())... 
Listening on http://localhost:2001/ 
Server running at: http://<guid>:7667 

When I request the root of my application, I get a reply from the NodeJS server. However, for some routes, I want to make a call to the Python part. I've succesfully done this locally, by using Node's http. However, when doing this on Heroku, I receive the following error:

connect ECONNREFUSED 127.0.0.1:2001

When I run this project locally in Heroku (via the CLI tool heroku local), it works perfectly. Any ideas on how I can get this to work?


回答1:


Finally found it. Dynos can't communicate with each other via HTTP, only via queues. I can't find it in the docs anymore, but they state it somewhere.

So I changed my Procfile to only run one dyno:

web: npm start & sh -c 'cd ./Python/ && export PYTHONPATH=. && python other.py'

Now I can make my call to 127.0.0.1:2001 without any problems.



来源:https://stackoverflow.com/questions/41979836/make-http-call-from-node-to-python-in-heroku-dyno

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!