You are not logged in.

#1 2016-04-18 14:46:28

Hossein Heydari
Member
From: Iran
Registered: 2015-12-16
Posts: 33

Python Flask script problem

Hi All

I installed all packages related to Flask and I wrote a code like this:

import flask
from flask import Flask
app = Flask(__name__)
@app.route("/")

def hello():
    return("Hello Arch forum, this is just flask test!")

if __name__ == "__main__":
    app.run(debug = True)

When I run it in terminal:

.---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-2-b55dfd89ccfb> in <module>()
      8 
      9 if __name__ == "__main__":
---> 10     app.run(debug = True)

/usr/lib/python3.5/site-packages/flask/app.py in run(self, host, port, debug, **options)
    770         options.setdefault('use_debugger', self.debug)
    771         try:
--> 772             run_simple(host, port, self, **options)
    773         finally:
    774             # reset the first request information if the development server

/usr/lib/python3.5/site-packages/werkzeug/serving.py in run_simple(hostname, port, application, use_reloader, use_debugger, use_evalex, extra_files, reloader_interval, reloader_type, threaded, processes, request_handler, static_files, passthrough_errors, ssl_context)
    672             s = socket.socket(address_family, socket.SOCK_STREAM)
    673             s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
--> 674             s.bind((hostname, port))
    675             if hasattr(s, 'set_inheritable'):
    676                 s.set_inheritable(True)

OSError: [Errno 98] Address already in use

Why am I getting this Error? How should I fix it? if Flask is a Python web framework programming How should I see my codes in firefox?

Offline

#2 2016-04-18 18:52:07

dmerej
Member
From: Paris
Registered: 2016-04-09
Posts: 101
Website

Re: Python Flask script problem

Well, the error message says it :

OSError: [Errno 98] Address already in use

By default flaks listens to the 5000 port, you may want to check if you have a process listening at this address, and maybe kill it

You can install netstat from the net-tools package and then run something like:

sudo netstat --program --listening --numeric  --tcp

Responsible Coder, Python Fan, Rust enthusiast

Offline

#3 2016-04-19 01:03:50

Hossein Heydari
Member
From: Iran
Registered: 2015-12-16
Posts: 33

Re: Python Flask script problem

See output:

[hossein@ArchLinux ~]$ sudo netstat --program --listening --numeric  --tcp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:60013         0.0.0.0:*               LISTEN      9785/python3        
tcp        0      0 127.0.0.1:46415         0.0.0.0:*               LISTEN      9785/python3        
tcp        0      0 127.0.0.1:40080         0.0.0.0:*               LISTEN      9785/python3        
tcp        0      0 127.0.0.1:43891         0.0.0.0:*               LISTEN      9785/python3        
tcp        0      0 127.0.0.1:8888          0.0.0.0:*               LISTEN      854/python3         
tcp        0      0 127.0.0.1:9050          0.0.0.0:*               LISTEN      801/tor             
tcp        0      0 127.0.0.1:49120         0.0.0.0:*               LISTEN      9785/python3        
tcp        0      0 127.0.0.1:41280         0.0.0.0:*               LISTEN      804/python2         
tcp        0      0 127.0.0.1:5000          0.0.0.0:*               LISTEN      9785/python3        
tcp        0      0 127.0.0.1:36460         0.0.0.0:*               LISTEN      9785/python3        
tcp6       0      0 ::1:8888                :::*                    LISTEN      854/python3         
[hossein@ArchLinux ~]$ 

Python3 is using that port but still problem!

Offline

#4 2016-04-19 12:59:20

anatolik
Developer
Registered: 2012-09-27
Posts: 458

Re: Python Flask script problem

Hossein Heydari wrote:

Python3 is using that port but still problem!

It is the problem your Flask application tries to tell you. Some other Python application already uses this port so your example above cannot use it.

Either find the application that already uses port 5000 and kill it or change your Flask app to use different port.


Read it before posting http://www.catb.org/esr/faqs/smart-questions.html
Ruby gems repository done right https://bbs.archlinux.org/viewtopic.php?id=182729
Fast initramfs generator with security in mind https://wiki.archlinux.org/index.php/Booster

Offline

Board footer

Powered by FluxBB