2016-10-06 55 views
0

我已經開始製作一個在Heroku上運行的Node服務器。直到我嘗試使用(非官方)Duolingo API時,它工作正常。我寫了下面的Python腳本連接到API:Heroku上的Python和Node.js

import duolingo 
import simplejson as json 

lingo = duolingo.Duolingo('harleyrowland') 
print json.dumps(lingo.get_user_info()) 

和我的節點服務器使用它使用以下命令:

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

module.exports = { 
    getData: function(callback){ 
    python.run('duoScript.py', function (err, results) { 
     console.log(err); 
     console.log(results); 
     var res = JSON.parse(results); 
     var language = res.language_data.es.language_string; 
     var streak = res.language_data.es.streak; 
     var level = res.language_data.es.level; 
     var levelPerecentage = res.language_data.es.level_percent; 
     var fluency = res.language_data.es.fluency_score; 
     var nextLesson = res.language_data.es.next_lesson.skill_title; 
     return callback({language, streak, level, levelPerecentage, fluency, nextLesson}); 
    }); 
    } 
} 

所有本地工作完全正常。

當我推開這Heroku的,代碼沒有工作,我開始在Heroku的日誌中出現以下錯誤:

{ [Error: ImportError: No module named duolingo] 
    2016-10-06T00:02:32.133315+00:00 app[web.1]: traceback: 'Traceback (most recent call last):\n File "duoScript.py", line 1, in <module>\n import duolingo\nImportError: No module named duolingo\n', 
    executable: 'python', 
    options: null, 
    script: 'duoScript.py', 
    args: null, 
    exitCode: 1 
} 

正因爲如此,我去了Heroku API,發現我需要添加一個requirements.txt文件。所以我做了:

duolingo-api==0.3 
simplejson==3.8.2 

哪些仍然沒有工作。後來我發現this答案,並增加了一個.buildpacks文件:

https://github.com/heroku/heroku-buildpack-python.git 
https://github.com/heroku/heroku-buildpack-nodejs.git 

,我仍然得到同樣的錯誤。

任何想法是什麼導致此錯誤?

更新1

以爲我會展示我Procfile太櫃面這是問題:

web: node index.js 
pipinstall: pip install -r requirements.txt 

更新2

輸出的git push heroku masterpipinstall

$ git push heroku master 
Counting objects: 3, done. 
Delta compression using up to 4 threads. 
Compressing objects: 100% (2/2), done. 
Writing objects: 100% (3/3), 288 bytes | 0 bytes/s, done. 
Total 3 (delta 1), reused 0 (delta 0) 
remote: Compressing source files... done. 
remote: Building source: 
remote: 
remote: -----> Node.js app detected 
remote: 
remote: -----> Creating runtime environment 
remote:   
remote:  NPM_CONFIG_LOGLEVEL=error 
remote:  NPM_CONFIG_PRODUCTION=true 
remote:  NODE_ENV=production 
remote:  NODE_MODULES_CACHE=true 
remote: 
remote: -----> Installing binaries 
remote:  engines.node (package.json): 5.9.1 
remote:  engines.npm (package.json): unspecified (use default) 
remote:   
remote:  Downloading and installing node 5.9.1... 
remote:  Using default npm version: 3.7.3 
remote: 
remote: -----> Restoring cache 
remote:  Loading 2 from cacheDirectories (default): 
remote:  - node_modules 
remote:  - bower_components (not cached - skipping) 
remote: 
remote: -----> Building dependencies 
remote:  Installing node modules (package.json) 
remote: 
remote: -----> Caching build 
remote:  Clearing previous node cache 
remote:  Saving 2 cacheDirectories (default): 
remote:  - node_modules 
remote:  - bower_components (nothing to cache) 
remote: 
remote: -----> Build succeeded! 
remote:  ├── [email protected] extraneous 
remote:  ├── [email protected] extraneous 
remote:  ├── [email protected] 
remote:  ├── [email protected] 
remote:  ├── [email protected] 
remote:  ├── [email protected] 
remote:  ├── [email protected] 
remote:  └── [email protected] 
remote:   
remote: -----> Discovering process types 
remote:  Procfile declares types -> web 
remote: 
remote: -----> Compressing... 
remote:  Done: 13M 
remote: -----> Launching... 
remote:  Released v25 
remote:  https://arcane-anchorage-33274.herokuapp.com/ deployed to Heroku 
remote: 
remote: Verifying deploy... done. 
+0

從Procfile刪除'pipinstall'併發布您的混帳推的輸出 –

+0

@RetoAebersold剛剛更新我的問題 – Haych

+0

你做到以下幾點: Heroku的配置:設置BUILDPACK_URL = https://github.com/ddollar/heroku-buildpack-multi –

回答

4

嘗試刪除已棄用的heroku-buildpack-multi和使用Heroku的buildpacks命令:

$ heroku buildpacks:add --index 1 heroku/nodejs 
$ heroku buildpacks:add --index 2 heroku/python