Search code examples
pythonwebcgiweb-scrapingcgi-bin

Python Deployment To CGI Host?


I have developed a CGI Python application, it works on a local server, but how do I compile it to run it on a remote Python CGI host?

The application uses

import cgitb
import cgi
import requests
import cookielib
import bleach
import re

Solution

  • Assuming this structure:

    (root)
     |- html
     |  |- .htaccess
     |  |- ...
     |- lib
        |- lib1
        |  |- script1.py
        |- lib2
           |- script2.py
    
    import sys
    for path in ("/lib/lib1", "/lib/lib2",...):
        if not path in sys.path:
            sys.path.append(path)
    
    import script1        # should work with the right paths
    

    Aaaand... many providers require certain stuff in '.htaccess' file to make python files executable.