Internal Server Error!
Hi all!
Back again here with a flask question. I am a beginner and learn some awesome things from reddit (how to legit code).
Here is my code that I have grabbed certain information from an API that I am now trying to host locally through flask.
from flask import Flask, render_template
import httplib
import json
app = Flask(__name__)
@app.route('/')
def index():
connection = httplib.HTTPConnection('api.football-data.org')
headers = {'X-Auth-Token': 'this is my api token here', 'X-Response-Control': 'minified'}
connection.request('GET', '/v1/competitions/426/leagueTable', None, headers)
response = json.loads(connection.getresponse().read().decode())
return response
if __name__ == '__main__':
app.run()
When I run 127.0.0.1:5000 I get:
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.
Here is what my server is telling me!
MacBooks-MBP:Football macbookpro13$ python Footy_Web.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[2016-12-20 13:58:17,493] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/Library/Python/2.7/site-packages/flask/app.py", line 1642, in full_dispatch_request
response = self.make_response(rv)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1746, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "/Library/Python/2.7/site-packages/werkzeug/wrappers.py", line 847, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "/Library/Python/2.7/site-packages/werkzeug/wrappers.py", line 57, in _run_wsgi_app
return _run_wsgi_app(*args)
File "/Library/Python/2.7/site-packages/werkzeug/test.py", line 871, in run_wsgi_app
app_rv = app(environ, start_response)
TypeError: 'dict' object is not callable
127.0.0.1 - - [20/Dec/2016 13:58:17] "GET / HTTP/1.1" 500 -
I should mention this code works outside of the flask framework!
EDIT:
I HAVE SOLVED THIS THANKS TO STACKOVERFLOW:
I NEEDED TO print(jsonify(response))
/r/flask
https://redd.it/5jfdnx
Hi all!
Back again here with a flask question. I am a beginner and learn some awesome things from reddit (how to legit code).
Here is my code that I have grabbed certain information from an API that I am now trying to host locally through flask.
from flask import Flask, render_template
import httplib
import json
app = Flask(__name__)
@app.route('/')
def index():
connection = httplib.HTTPConnection('api.football-data.org')
headers = {'X-Auth-Token': 'this is my api token here', 'X-Response-Control': 'minified'}
connection.request('GET', '/v1/competitions/426/leagueTable', None, headers)
response = json.loads(connection.getresponse().read().decode())
return response
if __name__ == '__main__':
app.run()
When I run 127.0.0.1:5000 I get:
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.
Here is what my server is telling me!
MacBooks-MBP:Football macbookpro13$ python Footy_Web.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[2016-12-20 13:58:17,493] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/Library/Python/2.7/site-packages/flask/app.py", line 1642, in full_dispatch_request
response = self.make_response(rv)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1746, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "/Library/Python/2.7/site-packages/werkzeug/wrappers.py", line 847, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "/Library/Python/2.7/site-packages/werkzeug/wrappers.py", line 57, in _run_wsgi_app
return _run_wsgi_app(*args)
File "/Library/Python/2.7/site-packages/werkzeug/test.py", line 871, in run_wsgi_app
app_rv = app(environ, start_response)
TypeError: 'dict' object is not callable
127.0.0.1 - - [20/Dec/2016 13:58:17] "GET / HTTP/1.1" 500 -
I should mention this code works outside of the flask framework!
EDIT:
I HAVE SOLVED THIS THANKS TO STACKOVERFLOW:
I NEEDED TO print(jsonify(response))
/r/flask
https://redd.it/5jfdnx
reddit
Internal Server Error! • /r/flask
Hi all! Back again here with a flask question. I am a beginner and learn some awesome things from reddit (how to legit code). Here is my code...
Visualize missing data with the missingno package
https://github.com/ResidentMario/missingno
/r/pystats
https://redd.it/4c8vnb
https://github.com/ResidentMario/missingno
/r/pystats
https://redd.it/4c8vnb
GitHub
GitHub - ResidentMario/missingno: Missing data visualization module for Python.
Missing data visualization module for Python. Contribute to ResidentMario/missingno development by creating an account on GitHub.
Django Development on OSX - Best Practices?
I have very little experience with OSX, but work is getting me a macbook pro.
I have 20 years experience with windows and maybe effectively 2-3 years with linux.
I use Windows for work. I've learned three things about python/django development on windows:
1. It's possible
2. Don't. It's a trap!
3. Windows is great for running VMs which allow you to use Vagrant or a remote interpreter.
Just learned that I'm getting a macbook pro for work, so I figured I'd put a little thought into my work environment before I get it. Might be a few weeks with the holidays.
For the most part, I use Pycharm Professional for django development.
Are there pitfalls or best practices developing django on OSX?
/r/django
https://redd.it/5jk12r
I have very little experience with OSX, but work is getting me a macbook pro.
I have 20 years experience with windows and maybe effectively 2-3 years with linux.
I use Windows for work. I've learned three things about python/django development on windows:
1. It's possible
2. Don't. It's a trap!
3. Windows is great for running VMs which allow you to use Vagrant or a remote interpreter.
Just learned that I'm getting a macbook pro for work, so I figured I'd put a little thought into my work environment before I get it. Might be a few weeks with the holidays.
For the most part, I use Pycharm Professional for django development.
Are there pitfalls or best practices developing django on OSX?
/r/django
https://redd.it/5jk12r
reddit
Django Development on OSX - Best Practices? • /r/django
I have very little experience with OSX, but work is getting me a macbook pro. I have 20 years experience with windows and maybe effectively 2-3...
Cool New Features & Syntax Changes in Python 3.6 (+video overview)
https://dbader.org/blog/cool-new-features-in-python-3-6#
/r/Python
https://redd.it/5jkv4w
https://dbader.org/blog/cool-new-features-in-python-3-6#
/r/Python
https://redd.it/5jkv4w
dbader.org
Cool new features in Python 3.6 – dbader.org
Python 3.6 adds a couple of new features and improvements that’ll affect the day to day work of Python coders. In this article I’ll give you an overview of the new features I found the most interesting.
Which NYC borough has the most noise complaints?
https://github.com/jvns/pandas-cookbook/blob/master/cookbook/Chapter%203%20-%20Which%20borough%20has%20the%20most%20noise%20complaints%20%28or,%20more%20selecting%20data%29.ipynb
/r/JupyterNotebooks
https://redd.it/49lbze
https://github.com/jvns/pandas-cookbook/blob/master/cookbook/Chapter%203%20-%20Which%20borough%20has%20the%20most%20noise%20complaints%20%28or,%20more%20selecting%20data%29.ipynb
/r/JupyterNotebooks
https://redd.it/49lbze
GitHub
jvns/pandas-cookbook
pandas-cookbook - Recipes for using Python's pandas library
Three ways to do a two-way ANOVA with Python
http://www.marsja.se/three-ways-to-carry-out-2-way-anova-with-python/
/r/pystats
https://redd.it/4bwnr8
http://www.marsja.se/three-ways-to-carry-out-2-way-anova-with-python/
/r/pystats
https://redd.it/4bwnr8
Erik Marsja
Three ways to do a two-way ANOVA with Python - Erik Marsja
This is a tutorial on how to carry out two-way ANOVA for independent measures using Python. It covers calculation itself, using Statsmodels, and Pyvttbl.
Question on the Front-End (Bootstrap Admin Template?)
Writing a business-logic app, with just a few models that have relationships. Django works great for the backend, love the model relationships/inheritance, and so far we've had moderate success with using basic Django (or crispy) forms, and DRF to host the ListView API and DataTables.
Was thinking of implementing something along the lines of a BootStrap Admin Template, so that our internal "Site" would start to look more like a Web Application. We'll need a dashboard, some metrics, charts/graphs, but also what's really important is the form interaction, being able to edit a parent record while seeing it's related children records, having an edit view and a read-only view, etc.
Is a Bootstrap template the way to go? Am I way overcomplicating this? Do I need to learn AngularJS or React?
I've got most of the functionality worked out, Workflow, Required Fields, Editable Fields, Audit Trail, Time Stamps, etc... just really struggling with a front-end that doesn't look like it's from the 90s.
/r/django
https://redd.it/5jlenx
Writing a business-logic app, with just a few models that have relationships. Django works great for the backend, love the model relationships/inheritance, and so far we've had moderate success with using basic Django (or crispy) forms, and DRF to host the ListView API and DataTables.
Was thinking of implementing something along the lines of a BootStrap Admin Template, so that our internal "Site" would start to look more like a Web Application. We'll need a dashboard, some metrics, charts/graphs, but also what's really important is the form interaction, being able to edit a parent record while seeing it's related children records, having an edit view and a read-only view, etc.
Is a Bootstrap template the way to go? Am I way overcomplicating this? Do I need to learn AngularJS or React?
I've got most of the functionality worked out, Workflow, Required Fields, Editable Fields, Audit Trail, Time Stamps, etc... just really struggling with a front-end that doesn't look like it's from the 90s.
/r/django
https://redd.it/5jlenx
reddit
Question on the Front-End (Bootstrap Admin Template?) • /r/django
Writing a business-logic app, with just a few models that have relationships. Django works great for the backend, love the model...
Strategy for creating/running tests that do not use a database
I have a flask app that uses a database. I am running my tests but many of the fixtures create data in the database and use that for the tests. Is there a good strategy for avoiding having the tests rely on data in the database?
Maybe having fixtures that create objects in the session, using them for the test and then deleting them from the session?
Any ideas?
/r/flask
https://redd.it/5jmrxu
I have a flask app that uses a database. I am running my tests but many of the fixtures create data in the database and use that for the tests. Is there a good strategy for avoiding having the tests rely on data in the database?
Maybe having fixtures that create objects in the session, using them for the test and then deleting them from the session?
Any ideas?
/r/flask
https://redd.it/5jmrxu
reddit
Strategy for creating/running tests that do not use a... • /r/flask
I have a flask app that uses a database. I am running my tests but many of the fixtures create data in the database and use that for the tests. Is...
Difference between running flask in debug mode vs regular mode
I was just curious what are the main differences running in debug_mode vs regular mode minus the updating of the code without having to rerun and the debuging mode nicely showing errors etcc..
Thanks
/r/flask
https://redd.it/5jlgl1
I was just curious what are the main differences running in debug_mode vs regular mode minus the updating of the code without having to rerun and the debuging mode nicely showing errors etcc..
Thanks
/r/flask
https://redd.it/5jlgl1
reddit
Difference between running flask in debug mode vs... • /r/flask
I was just curious what are the main differences running in debug_mode vs regular mode minus the updating of the code without having to rerun and...
tmuxp — tmuxinator clone i wrote in python
https://tmuxp.git-pull.com/
/r/Python
https://redd.it/5jlofy
https://tmuxp.git-pull.com/
/r/Python
https://redd.it/5jlofy
tmuxp
Session manager for tmux, which allows users to save and load tmux sessions through simple configuration files. Powered by libtmux. Python Package Docs Build status Code Coverage License New to tmu...
Has anyone got a job without a degree CompSci degree ?
Basic question. Im learning python right now and its starting to make sense. Just wondering if you can land a job if you have a good portfolio of programs you have written ?
/r/Python
https://redd.it/5jn9gg
Basic question. Im learning python right now and its starting to make sense. Just wondering if you can land a job if you have a good portfolio of programs you have written ?
/r/Python
https://redd.it/5jn9gg
reddit
Has anyone got a job without a degree CompSci degree ? • /r/Python
Basic question. Im learning python right now and its starting to make sense. Just wondering if you can land a job if you have a good portfolio of...
Estimate distribution of d prime in signal detection
I want to use maximum likelihood to derive the estimate d prime for extreme result of signal detection.
* The noise centers at 0 and signal centers at d prime. Both noise and signal have the same variance, and we assume it as 1 for now.
* Criterion is always half of d prime.
The goal is to find the probability of 'no error' data: zero counts for Miss and FA.
As I simulate use d prime from 0 to 40 in step size of 0.5, I found a probability shape like [graph](https://github.com/adowaconan/simulation/blob/master/lab%202.ipynb) in **Q3A**.
How do I derive the maximum likelihood estimate of d prime based on a given data set?
Say give a data set that is 'no error':
hit = 100, miss = 0, false alarm = 0, correct rejection = 100.
For this data set, the # of signal and # of noise are the same as 100.
I used Bernoulli method to calculate the maximum likelihood for d prime and get infinity by hand, but I don't know how to do it in python and not sure if it is correct.
Any suggestions?
/r/pystats
https://redd.it/4bai6p
I want to use maximum likelihood to derive the estimate d prime for extreme result of signal detection.
* The noise centers at 0 and signal centers at d prime. Both noise and signal have the same variance, and we assume it as 1 for now.
* Criterion is always half of d prime.
The goal is to find the probability of 'no error' data: zero counts for Miss and FA.
As I simulate use d prime from 0 to 40 in step size of 0.5, I found a probability shape like [graph](https://github.com/adowaconan/simulation/blob/master/lab%202.ipynb) in **Q3A**.
How do I derive the maximum likelihood estimate of d prime based on a given data set?
Say give a data set that is 'no error':
hit = 100, miss = 0, false alarm = 0, correct rejection = 100.
For this data set, the # of signal and # of noise are the same as 100.
I used Bernoulli method to calculate the maximum likelihood for d prime and get infinity by hand, but I don't know how to do it in python and not sure if it is correct.
Any suggestions?
/r/pystats
https://redd.it/4bai6p
GitHub
adowaconan/simulation
Contribute to simulation development by creating an account on GitHub.
Security release: Jupyter Notebook 4.3.1
http://blog.jupyter.org/2016/12/21/jupyter-notebook-4-3-1/
/r/IPython
https://redd.it/5jmnwy
http://blog.jupyter.org/2016/12/21/jupyter-notebook-4-3-1/
/r/IPython
https://redd.it/5jmnwy
Project Jupyter
Security release: Jupyter Notebook 4.3.1
We have just released Jupyter Notebook 4.3.0 and 4.3.1 with some important security fixes. You can check out the changelog for more details on the many fixes and improvements. I'm going to focus on the security changes in this post. 4.3.0: Token authentication…
serving static files help error
So I have a flask app that takes a csv then display the graph of the csv my problem is that the graph it displays does not update when I change the csv to something else even though I have route defined and it is called
@app.route("/static/<figName>",methods=['post','get'])
def renderFigure(figName):
fileLocation = os.getcwd()+"\\static\\"
print("rendering image",figName)
return send_from_directory(fileLocation, figName)
heres the html
<img src="{{ url_for('static', filename=figName) }}"} alt="..." class="img-thumbnail">
It always displays the same graph the first one I dont know why even though in the actual directory the file is updated any help is greatly appreciated.
Sorry the error is that it my other route does not call this one so my question is how to call it
@app.route("/fileAnalysis",methods=['post','get'])
def fileAnalysis():
if request.method=="POST":
option = request.form['graphSelection']
f =request.files['fileUpload']
currentDir = os.getcwd()
if not f:
print("not file entered")
elif option!="Average likes for top commentators":
file_contents = f.stream.read().decode("latin-1")
print("before writing to the file")
newFile= open("statsFile.csv","w+",encoding='latin-1')
newFile.write(file_contents)
newFile.close()
print("wrote to file ")
print(type(file_contents))
if option=="Comments by hour of the day":
print("in top comments of hour of the day")
groupByHour.saveHourGraph("statsFile.csv")
return render_template("graph.html",figName=("commentsByHour.png"),title="Comments per hour of the day")
elif option=="Top Commentators":
topComments.makeTopCommentsGraph("statsFile.csv")
return render_template("graph.html",figName=("topCommentators.png"),title="top 100 commentators and the number of comments over a period of time")
elif option=="General Statistics":
dfComments = pd.read_csv("statsFile.csv", parse_dates=['comment_published'],encoding="latin-1")
print("hello world statistics")
return render_template("generalStats.html",dFrame=dfComments.describe(percentiles=[0.25,0.5,0.75,0.85,0.9,0.95,0.97,0.98,0.99]).to_html(classes="table table-striped"),title="General statistics on the file including mean ,standard deviation and percentiles of count of comment")
elif option=="Average likes for top commentators":
print("in average likes for top commentators need 2 files")
postsFile = request.files['fileUploadLikes']
if not f or not postsFile:
print("need to enter both files")
else:
file_contents = f.stream.read().decode("latin-1")
filePostsContents= postsFile.stream.read().decode("latin-1")
print("before writing to the file")
newFile= open("statsFile.csv","w+",encoding='latin-1')
newFile.write(file_contents)
newFile.close()
newFile= open("postsFile.csv","w+",encoding='utf-8')
newFile.write(filePostsContents)
newFile.close()
print("wrote to both files")
averageComments.getAverageLikes("statsFile.csv","postsFile.csv")
return render_template("graph.html",figName=("averageComments.png"),title="Average Comments for top 500 users")
print(option)
print("posted file ")
return render_template("fileAnalysis.html")
/r/flask
https://redd.it/5j8dwy
So I have a flask app that takes a csv then display the graph of the csv my problem is that the graph it displays does not update when I change the csv to something else even though I have route defined and it is called
@app.route("/static/<figName>",methods=['post','get'])
def renderFigure(figName):
fileLocation = os.getcwd()+"\\static\\"
print("rendering image",figName)
return send_from_directory(fileLocation, figName)
heres the html
<img src="{{ url_for('static', filename=figName) }}"} alt="..." class="img-thumbnail">
It always displays the same graph the first one I dont know why even though in the actual directory the file is updated any help is greatly appreciated.
Sorry the error is that it my other route does not call this one so my question is how to call it
@app.route("/fileAnalysis",methods=['post','get'])
def fileAnalysis():
if request.method=="POST":
option = request.form['graphSelection']
f =request.files['fileUpload']
currentDir = os.getcwd()
if not f:
print("not file entered")
elif option!="Average likes for top commentators":
file_contents = f.stream.read().decode("latin-1")
print("before writing to the file")
newFile= open("statsFile.csv","w+",encoding='latin-1')
newFile.write(file_contents)
newFile.close()
print("wrote to file ")
print(type(file_contents))
if option=="Comments by hour of the day":
print("in top comments of hour of the day")
groupByHour.saveHourGraph("statsFile.csv")
return render_template("graph.html",figName=("commentsByHour.png"),title="Comments per hour of the day")
elif option=="Top Commentators":
topComments.makeTopCommentsGraph("statsFile.csv")
return render_template("graph.html",figName=("topCommentators.png"),title="top 100 commentators and the number of comments over a period of time")
elif option=="General Statistics":
dfComments = pd.read_csv("statsFile.csv", parse_dates=['comment_published'],encoding="latin-1")
print("hello world statistics")
return render_template("generalStats.html",dFrame=dfComments.describe(percentiles=[0.25,0.5,0.75,0.85,0.9,0.95,0.97,0.98,0.99]).to_html(classes="table table-striped"),title="General statistics on the file including mean ,standard deviation and percentiles of count of comment")
elif option=="Average likes for top commentators":
print("in average likes for top commentators need 2 files")
postsFile = request.files['fileUploadLikes']
if not f or not postsFile:
print("need to enter both files")
else:
file_contents = f.stream.read().decode("latin-1")
filePostsContents= postsFile.stream.read().decode("latin-1")
print("before writing to the file")
newFile= open("statsFile.csv","w+",encoding='latin-1')
newFile.write(file_contents)
newFile.close()
newFile= open("postsFile.csv","w+",encoding='utf-8')
newFile.write(filePostsContents)
newFile.close()
print("wrote to both files")
averageComments.getAverageLikes("statsFile.csv","postsFile.csv")
return render_template("graph.html",figName=("averageComments.png"),title="Average Comments for top 500 users")
print(option)
print("posted file ")
return render_template("fileAnalysis.html")
/r/flask
https://redd.it/5j8dwy
reddit
serving static files help error • /r/flask
So I have a flask app that takes a csv then display the graph of the csv my problem is that the graph it displays does not update when I change...
What’s will be new in matplotlib — Matplotlib 2.0.0rc2 documentation
http://matplotlib.org/2.0.0rc2/users/whats_new.html
/r/IPython
https://redd.it/5jnw2y
http://matplotlib.org/2.0.0rc2/users/whats_new.html
/r/IPython
https://redd.it/5jnw2y
Missing data visualizations in Python?
Is there a tool for plotting missing data entries for a dataset in Python? I am thinking about something like [this](https://www.researchgate.net/profile/Bo_Tranberg/publication/277776292/figure/fig2/Figure-3-Matrix-plot-of-missing-data-cases-sorted-by-number-of-persons-with-the-name.png).
R seems to have [something](http://www.inside-r.org/packages/cran/mi/docs/missing.pattern.plot) like this, but I haven't tracked down a Python equivalent.
/r/pystats
https://redd.it/4azhee
Is there a tool for plotting missing data entries for a dataset in Python? I am thinking about something like [this](https://www.researchgate.net/profile/Bo_Tranberg/publication/277776292/figure/fig2/Figure-3-Matrix-plot-of-missing-data-cases-sorted-by-number-of-persons-with-the-name.png).
R seems to have [something](http://www.inside-r.org/packages/cran/mi/docs/missing.pattern.plot) like this, but I haven't tracked down a Python equivalent.
/r/pystats
https://redd.it/4azhee
Analyzing Golden State Warriors' passing network using GraphFrames in Spark
http://opiateforthemass.es/articles/analyzing-golden-state-warriors-passing-network-using-graphframes-in-spark/
/r/pystats
https://redd.it/4al1ps
http://opiateforthemass.es/articles/analyzing-golden-state-warriors-passing-network-using-graphframes-in-spark/
/r/pystats
https://redd.it/4al1ps
Opiate for the masses
Analyzing Golden State Warriors' passing network using GraphFrames in Spark
and interactive chart with networkD3