Forums

[FLASK] Help ..

Hello guys,

I found Pythonanywhere few days ago and it is awasome ! I'm a frenchman, so sorry for my bad english ^^

I have some problem with Flask :

I want to developp and Artificial Neural Network for Tennis Prediction. It is working fine on my computer, also on the Pythonanywhere console, but not working as soon as i tryed to request the result from URL with Flask.

The function that I want to work with Flask is "who_win(j, jj)" For example : who_win("Roger Federer", "Rafael Nadal"). (Need to be well spelled)

I'm totaly new with Flask, maybe i didn't understand something.

Thank you in advance for your help !

Vincent

Hi Vincent,

I would suggest setting up a sample flask app first from the webapps tab, and then making sure you can say change the sample hello world endpoint to show something else. After you have that working, you can get the flask app to import and run your code.

Hello Conrad ! First, thank you for your answer, I appreciate

I have already set up an simple Flask App. Hello Word is working fine. I also create other functions with and without parameters. Everything is working fine but my "who_win(J1,J2)".

I'm working on it to find a solution

Vincent

Hello Conrad ! First, thank you for your answer, I appreciate

I have already set up an simple Flask App. Hello Word is working fine. I also create other functions with and without parameters. Everything is working fine but my "who_win(J1,J2)".

I'm working on it to find a solution

Vincent

Can you give more details? eg: what is the error message, how is it not working?

I think I found a first problem here :

It seems like the script is unable to read from another txt file in the same directory :/

2017-07-28 13:05:40,062: File "/home/betoux/mysite/flask_app.py", line 330, in GetPlayerListLocal 2017-07-28 13:05:40,062: return pickle.load( open( "player_list.txt", "rb" ) ) 2017-07-28 13:05:40,062: FileNotFoundError: [Errno 2] No such file or directory: 'player_list.txt'

def GetPlayerListLocal(): return pickle.load( open( "player_list.txt", "rb" ) )

Have you set the working directory of your web app to /home/betoux/mysite? Because that's where relative paths are based.

Hello Gleen

When you say "Set", do you mean that I have to do something or just wondering if I am working on /home/betoux/mysite directory ?

I am working on : /home/betoux/mysite/flask_app.py

There is a field on your web app called Working directory. Edit it. Be aware that this may change how your imports work (depending on how your app is configured and how you do your imports) Alternatively, you could just use the full path to the file you want to read and not rely on the working directory.

Everything working fine ! You can try it ;)

For example : http://betoux.pythonanywhere.com/who/Roger%20Federer/Rafael%20Nadal

I'll upgrade my account in few week ! Verry good job

[0] = Player 1 win, [1] = Player 2 win

x * e-xxx ~= 0