1

This is the Python code that i am using:

@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

When i go to http://localhost:5000/getInformation everything seems ok no error message is being shown and also it is doing what it should do. However when i put it on my server and run it there i receive an error message.

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.

If it is any help, i am using Heroku to upload the code to the server. I am also using Heroku's built in command foreman start to try the code locally.

EDIT1

Solved it thanks to the comments below by checking the logs. The error was:

IOError: Error reading file 'http://127.0.0.1/': failed to load external entity "http://127.0.0.1/"

Then it struck to me its a local address that i was running on my pc. Commenting out

urlList.append("http://127.0.0.1/")

Worked fine. Thank you

hamzah
  • 375
  • 2
  • 5
  • 17
  • 1
    figure out where the logs are stored and look in the log for the error that occured... or figure out how to run apps in debug mode on heroku – Joran Beasley Mar 09 '15 at 17:58
  • But can there be anything bad in the code? Since its working locally why not remotly? @JoranBeasley – hamzah Mar 09 '15 at 18:00
  • of coarse ... not only can there ... there obviously is since you get an error (perhaps you are missing an import or they use a different python on heroku or you are trying to access a path that does not exist ...etc ... it will likely be a very easy fix ... once you figure out what the problem is – Joran Beasley Mar 09 '15 at 18:01
  • I think you can also do something like `app.debug = True` and get a better traceback (assuming it gets that far) ... add that line right after `app = Flask(__name__)` – Joran Beasley Mar 09 '15 at 18:04
  • [Enabling debug mode](http://stackoverflow.com/questions/8950674/debugging-a-flask-app-running-in-gunicorn), logging output to stdout [using `--log-file -`](https://devcenter.heroku.com/articles/python-gunicorn#adding-gunicorn-to-your-application-procfile) and viewing logs with [`heroku logs`](https://devcenter.heroku.com/articles/getting-started-with-django#view-the-logs) should work to get to the reason for your 500 Internal Server Error. – Lukas Graf Mar 09 '15 at 18:15
  • Thank you found the answer. – hamzah Mar 09 '15 at 18:32

0 Answers0