这是我正在使用的Python代码:
@app.route("/getInformation", methods=['GET'])
def domain():
urlList = []
urlList.append("http://gbgfotboll.se/serier/?scr=table&ftid=57109")
urlList.append("http://127.0.0.1/")
urlList.append("http://gbgfotboll.se/serier/?scr=table&ftid=57108")
date = '2015-04-18'
# use this in real mode: currentDate = (time.strftime("%Y-%m-%d"))
homeScore = "0"
awayScore = "0"
homeTeam = ""
awayTeam = ""
time_xpath = XPath("td[1]/span/span//text()[2]")
team_xpath = XPath("td[2]/a/text()")
league_xpath = XPath("//*[@id='content-primary']/h1//text()")
for url in urlList:
test = 2
rows_xpath = XPath("//*[@id='content-primary']/table/tbody/tr[td[1]/span/span//text()='%s']" % (date))
html = lxml.html.parse(url)
divName = league_xpath(html)[0]
trash, divisionName = divName.rsplit("- ")
dict[divisionName] = {}
for id,row in enumerate(rows_xpath(html)):
#time = time_xpath(row)[0].strip() #use this in real code
time = "1%d"%test +":00" # remove this later
test += 1 #remove this
test %= 3 # remove this later
team = team_xpath(row)[0]
homeTeam, awayTeam = team.split(" - ")
hour, minute = time.split(":")
newTime = timeConvert(hour, minute)
dict[divisionName].update({ id :{"time":str(newTime),"tempTime": time ,"homeTeam":homeTeam,"homeScore":homeScore, "awayTeam":awayTeam, "awayScore":awayScore, "events" :[] }})
with open('gameFile.txt', 'wb') as handle:
pickle.dump(dict, handle)
return Response(mimetype='application/json') //Is there a better way?
//Note i am not trying to send anything back. i just noticed when running locally not writing this gave me an internal server error
当我转到http://localhost:5000/getInformation时,一切似乎都没有显示错误消息,而且它正在做它应该做的事情。但是当我把它放在我的服务器上并运行它时,我收到一条错误消息。
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
如果有任何帮助,我使用Heroku将代码上传到服务器。我也使用Heroku的内置命令 foreman start 在本地试用代码。
EDIT1
通过查看日志,感谢下面的评论。错误是:
IOError: Error reading file 'http://127.0.0.1/': failed to load external entity "http://127.0.0.1/"
然后它给了我一个我在电脑上运行的本地地址。评论
urlList.append("http://127.0.0.1/")
工作得很好。谢谢