uwsgi: invalid option -- 'n' getopt_long() error

April 5, 2018 1.3k views
Nginx Debian

Hi, Iam stuck.
I am following a tutorial "Full stack full stack web application raspberry pi"
I am doing well, for a noob.
The pi is a zero w with rasbian lite stretch, installed nginx, postgresql, php7, python3, pip, flask,
installed uwsgi,
The tutorial states ```>cd /var/www/heating/

vim heating_nginx.conf```

the code is

server {
listen
80;
server_name localhost;
charset
utf-8;
client_max_body_size 75M;
location /static {
root /var/www/heating/;
}
location / { try_files $uri @heating; }
location @heating {
include uwsgi_params;
uwsgi_pass unix:/var/www/heating/heating_uwsgi.sock;
}
}
You are configuring an app

and then create the link >ln -s /var/www/labapp/labapp_nginx.conf /etc/nginx/conf.d/

and then >vim /var/www/labapp/labapp_uwsgi.ini

[uwsgi]
#application’s base folder
base = /var/www/heating
#python module to import
app = hello
module = %(app)
home = %(base)/venv
pythonpath = %(base)
#socket file’s location
socket = /var/www/heating/%n.sock
#permissions for the socket file
chmod-socket
= 666
#the variable that holds a flask application inside the module imported at line #6
callable = app
#location of log files
logto = /var/log/uwsgi/%n.log

then the bit where it all goes wrong:

uwsgi —ini /var/www/heating/heating_uwsgi.ini

here I get the error message
uwsgi: invalid option -- 'n' getopt_long() error

Can any body point me in the right direction
Kind regards
Paul

4 Answers

Looking at your configuration I am still not 100% sure where the 'n' option is coming from but I think it may be the last line of your ini file. I would try commenting out your logto line to see if the service starts properly.

It also looks like there is an extra linebreak that should be removed:

chmod-socket
= 666

should be

chmod-socket = 666
  • Hi @ryanpq,
    Thanks for you rapid reply, the chmod-socket = 666 was an error here in the posting, I have commented out #logto = /var/log/uwsgi/%n.log, but I still get the same error!
    Thanks again for your help
    Paul

    • Since I am no expert on uwsgi I reached out to a few others to see if they could spot anything.

      When entering your command are you using -- (two chars) or (one char) for the ini flag?

      You mentioned

      uwsgi —ini /var/www/heating/heating_uwsgi.ini
      

      but this command should use --

Hi again @ryanpq,
Thank you for your reply, I was using only one -, I made it two -- but got a huge error message!

*** Starting uWSGI 2.0.17 (32bit) on [Thu Apr  5 18:41:33 2018] ***
compiled with version: 6.3.0 20170516 on 04 April 2018 20:16:56
os: Linux-4.9.59+ #1047 Sun Oct 29 11:47:10 GMT 2017
nodename: heating3
machine: armv6l
clock source: unix
detected number of CPU cores: 1
current working directory: /home/pi
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3405
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
bind(): Permission denied [core/socket.c line 230]

So I took away the comment tag added sudo (as I am not in root) and got

[uWSGI] getting INI configuration from /var/www/heating/heating_uwsgi.ini

Which is what I think I want but when I look at http://192.168.0.12 I dont get "hello world" I get

"Internal Server Error"
Huge progress, nearly there!!!!!
Thank you so much for your help so far you're great!!!
Kind regards Paul

Hi again!

I have just look in the log file and found this:

WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
Python version: 2.7.13 (default, Nov 24 2017, 17:33:09)  [GCC 6.3.0 20170516]
Set PythonHome to /var/www/heating/venv
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x890b68
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 64392 bytes (62 KB) for 1 cores
*** Operational MODE: single process ***
added /var/www/heating/ to pythonpath.
Traceback (most recent call last):
  File "/var/www/heating/hello.py", line 1, in <module>
    from flask import Flask
ImportError: No module named flask
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 4377, cores: 1)
--- no python application found, check your startup logs for errors ---
[pid: 4377|app: -1|req: -1/1] 192.168.0.17 () {42 vars in 626 bytes} [Thu Apr  5 19:16:56 2018] GET / => generated 21 bytes in 9 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)

Does this mean anything to anybody?

Thanks for all your Help
Regards
Paul

Props to the person who mentioned there should be -- vs -. I had the same error and that solved my problem.

Paul,
I'm by no means an expert on these types of things. But I have suffered countless hours installing servers, backends, etc. on linux systems. The error I see there is:

ImportError: No module named flask

You should verify that flask is installed.

Have another answer? Share your knowledge.