我是新手。 我在AWS-Ubuntu上运行python web应用程序。我的目标是使用IP地址从浏览器访问此应用程序。
我已经配置了Apache Web服务器。下面是我的conf和wsgi文件。
.conf文件
<VirtualHost *:80>
ServerName 13.58.200.92
ServerAdmin admin@13.58.200.92
WSGIDaemonProcess catalog threads=5
WSGIProcessGroup catalog
WSGIScriptAlias / /var/www/catalog/catalog.wsgi
<Directory /var/www/catalog/Catalog/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/catalog/Catalog/static
<Directory /var/www/catalog/Catalog/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
.wsgi文件
#!/usr/bin/python3.5
import sys
import os
import logging
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
sys.path.insert(0,"/var/www/catalog/")
sys.path.append('/var/www/catalog/Catalog')
from Catalog import Employee as application
application.secret_key = 'super'
catalog.py
#!/usr/bin/env python3
from flask import Flask, render_template, url_for, request, redirect,
jsonify
from flask import flash
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from database_setup import Base, Department, Employee, User
from flask_httpauth import HTTPBasicAuth
# Anti Forgery State Token Code
from flask import session as login_session
import random
import string
# Import for 'Gconnect' step
from oauth2client.client import flow_from_clientsecrets, FlowExchangeError
import httplib2
import json
from flask import make_response
import requests
auth = HTTPBasicAuth()
CLIENT_ID = json.loads(open('/var/www/catalog/Catalog/client_secrets.json',
'r').read())['web']['client_id']
app = Flask(__name__)
# Connect to Database and create database session
engine = create_engine('postgresql://empcat:empcat@localhost/emp_catalog')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
@app.route('/')
def showLogin():
state = ''.join(random.choice(string.ascii_uppercase +
string.digits) for x in range(32))
login_session['state'] = state
return render_template('login.html', STATE=state)
@app.route('/gconnect', methods=['POST'])
def gconnect():
# Validate state token
if request.args.get('state') != login_session['state']:
response = make_response(json.dumps('Invalid state parameter.'),
401)
response.headers['Content-Type'] = 'application/json'
return response
# Obtain authorization code
程序出错时出现以下错误
TypeError: 'module' object is not callable
[Mon May 07 01:07:49.166142 2018] [wsgi:error] [pid 30509:tid
139706086553344] [remote 68.80.159.72:8163] mod_wsgi (pid=30509): Exception
occurred processing WSGI script '/var/www/catalog/catalog.wsgi'.
[Mon May 07 01:07:49.166236 2018] [wsgi:error] [pid 30509:tid
139706086553344] [remote 68.80.159.72:8163] TypeError: 'module' object is
not callable
在以下代码行
def showLogin()
def gconnect和所有其他
我试过评论这些行。但是在下一个def函数行得到相同的错误。