16

Does there exist any library that can serve a WSGI application as a FastCGI server, for Python 3? (So that nginx could then proxy requests to it?)

The Python 3 docs mention flup, but flup doesn't even install in Python 3:

% env3/bin/pip install flup
Downloading/unpacking flup
  Downloading flup-1.0.2.tar.gz (49kB): 49kB downloaded
  Running setup.py (path:/Users/me/tmp/env3/build/flup/setup.py) egg_info for package flup
    Traceback (most recent call last):
      File "", line 17, in 
      File "/Users/me/tmp/env3/build/flup/setup.py", line 2, in 
        from ez_setup import use_setuptools
      File "./ez_setup.py", line 98
        except pkg_resources.VersionConflict, e:
                                            ^
    SyntaxError: invalid syntax
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "", line 17, in 

  File "/Users/me/tmp/env3/build/flup/setup.py", line 2, in 

    from ez_setup import use_setuptools

  File "./ez_setup.py", line 98

    except pkg_resources.VersionConflict, e:

                                        ^

SyntaxError: invalid syntax

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in [snip]
Storing debug log for failure in [snip]
joce
  • 9,624
  • 19
  • 56
  • 74
Thanatos
  • 42,585
  • 14
  • 91
  • 146
  • A very quick Google search shows this in the first half dozen results. https://github.com/Pyha/flup-py3.3 – Graham Dumpleton May 05 '14 at 23:20
  • 1
    Found another one. It seems the original author Allan Saddi contributes significantly to it: http://hg.saddi.com/flup-py3.0/ – Nayuki Oct 20 '15 at 21:48
  • 2
    @Nayuki Yes indeed, `flup-py3` has an [unresolved issue](https://github.com/Pyha/flup-py3.3/issues/2) which has been standing open for a couple of years now. In [`flipflop`](https://pypi.python.org/pypi/flipflop), the great work of Allan Saddi was further simplified. – Serge Stroobandt Jan 04 '17 at 09:01

5 Answers5

9

There is now module called flup6. Install it using pip

./pip install flup6
SaidbakR
  • 13,303
  • 20
  • 101
  • 195
  • TypeError: sequence item 0: expected bytes, bytearray, or an object with the buffer interface, str found it not works with django 1.8 python 3.4 – eri Oct 12 '15 at 01:32
  • 1
    It looks like `flup6` is the only working `flup` replacement for Python 3. Tried `flup-py3` and `flipflop` on Python 3.5. – quasiyoke Apr 09 '16 at 21:32
  • @quasiyoke flipflop will not work in windows, as 'fcntl' can not work in windows. – Kingname Sep 26 '16 at 08:18
7

You can use flipflop. It's a simplified fork of flup (contains only the FastCGI part) and works fine with Python 3.

msiemens
  • 2,223
  • 1
  • 28
  • 38
  • Came across this on Google; this was exactly what I was looking for. Documentation is sparse, but the example on wikipedia is enough: http://en.wikipedia.org/wiki/Web_Server_Gateway_Interface#Example_application – HoboBen Nov 25 '14 at 02:12
  • For django, the fcgi on hostmonster.com asks for flup and pip could not able to install it. – SaidbakR Dec 29 '14 at 19:08
2

You can use flup-py3 to solve this problem, as :

pip3 install flup-py3

You may need super user privilge to execute this command.

yunfeng
  • 28
  • 1
  • 9
0

I am aware of two options

Both support Python 3 and both can create WSGI workers based on other web app code and can be served to NGINX.

As Graham Dumpleton mentioned, CherryPy talks to NGINX via HTTP protocol, while uWSGI talks the 'uwsgi' protocol to nginx instead of the HTTP protocol, although it does also support using HTTP as well. On the application side, both support hosting Python web applications via the WSGI API.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
Jan Vlcinsky
  • 42,725
  • 12
  • 101
  • 98
  • CherryPy relies on HTTP proxying. uWSGI would be a better choice of the two for nginx as recent nginx versions have support for uWSGI's custom protocol built in. – Graham Dumpleton May 05 '14 at 23:21
  • @GrahamDumpleton Good point, reviewed some descriptions, learned from your comment and updated my answer. I hope I understood your comment and linked descriptions correctly. – Jan Vlcinsky May 05 '14 at 23:57
0

Use flipflop instead

pip3 install --upgrade flipflop

flipflop is what did the trick for me. flup-py3 has an unresolved issue which has been standing open for a couple of years now.

Do not forget to edit the import line in your .fcgi script to reflect this change towards using flipflop.

Community
  • 1
  • 1
Serge Stroobandt
  • 28,495
  • 9
  • 107
  • 102