Я получил задание на одном из тренингов Python, которые я посещал. Я создал простое приложение для одного из моих проектов, используя flask 1.0 / python3.6. Моему заявлению необходимо добиться следующего:
- Вызов API из внутреннего приложения в колледже.
- Запустите запрос к базе данных в Oracle db и отобразите данные на веб-странице.
Я написал несколько функций в бэкэнде (python) для достижения этой цели и использую ajax для вызова этих функций. В флеш-сервере работает все хорошо. Теперь мне нужно перенести это на рабочий сервер, и я использую mod_wsgi вместе с httpd для достижения этой цели. После некоторой борьбы мое приложение запускается на рабочем сервере, однако мой код на python завершается с ошибкой 500 при выполнении обеих функций.
jquery.min.js:4 POST http://server.com/flaskprod/requestbots 500 (INTERNAL SERVER ERROR)
POST http://server.com/flaskprod/home 500 (INTERNAL SERVER ERROR)
Я проверил apache httpd error_log и вижу следующие ошибки.
Ошибки при вызове API:
[Mon Jul 02 13:48:41.302510 2018] [wsgi:error] [pid 18202] [remote 1.1.1.1:1212] File "/var/www/flask-prod/flaskprod.py", line 230, in createCM
[Mon Jul 02 13:48:41.302513 2018] [wsgi:error] [pid 18202] [remote 1.1.1.1:1212] r = requests.post(URL, auth=creds, data=json.dumps(DATAS), proxies=proxies, headers=headers)
[Mon Jul 02 13:48:41.302515 2018] [wsgi:error] [pid 18202] [remote 1.1.1.1:1212] File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 112, in post
[Mon Jul 02 13:48:41.302517 2018] [wsgi:error] [pid 18202] [remote 1.1.1.1:1212] return request('post', url, data=data, json=json, **kwargs)
[Mon Jul 02 13:48:41.302519 2018] [wsgi:error] [pid 18202] [remote 1.1.1.1:1212] File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 58, in request
[Mon Jul 02 13:48:41.302522 2018] [wsgi:error] [pid 18202] [remote 1.1.1.1:1212] return session.request(method=method, url=url, **kwargs)
[Mon Jul 02 13:48:41.302524 2018] [wsgi:error] [pid 18202] [remote 1.1.1.1:1212] File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
[Mon Jul 02 13:48:41.302526 2018] [wsgi:error] [pid 18202] [remote 1.1.1.1:1212] resp = self.send(prep, **send_kwargs)
[Mon Jul 02 13:48:41.302528 2018] [wsgi:error] [pid 18202] [remote 1.1.1.1:1212] File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
[Mon Jul 02 13:48:41.302530 2018] [wsgi:error] [pid 18202] [remote 1.1.1.1:1212] r = adapter.send(request, **kwargs)
[Mon Jul 02 13:48:41.302532 2018] [wsgi:error] [pid 18202] [remote 1.1.1.1:1212] File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 502, in send
[Mon Jul 02 13:48:41.302539 2018] [wsgi:error] [pid 18202] [remote 1.1.1.1:1212] raise ProxyError(e, request=request)
[Mon Jul 02 13:48:41.302546 2018] [wsgi:error] [pid 18202] [remote 1.1.1.1:1212] requests.exceptions.ProxyError: HTTPSConnectionPool(host='exampleee.com', port=443): Max retries exceeded with url: /api/now/change/change_req (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fac76d37eb8>: Failed to establish a new connection: [Errno 13] Permission denied',)))
Ошибки при запросе к базе данных:
[Mon Jul 02 13:51:23.148685 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
[Mon Jul 02 13:51:23.148687 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] response = self.full_dispatch_request()
[Mon Jul 02 13:51:23.148690 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
[Mon Jul 02 13:51:23.148693 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] rv = self.handle_user_exception(e)
[Mon Jul 02 13:51:23.148695 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
[Mon Jul 02 13:51:23.148698 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] reraise(exc_type, exc_value, tb)
[Mon Jul 02 13:51:23.148700 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] File "/usr/local/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
[Mon Jul 02 13:51:23.148702 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] raise value
[Mon Jul 02 13:51:23.148705 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
[Mon Jul 02 13:51:23.148707 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] rv = self.dispatch_request()
[Mon Jul 02 13:51:23.148709 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
[Mon Jul 02 13:51:23.148711 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] return self.view_functions[rule.endpoint](**req.view_args)
[Mon Jul 02 13:51:23.148714 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] File "/var/www/flask-prod/flaskprod.py", line 97, in get_cms_requested_for_approval
[Mon Jul 02 13:51:23.148716 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] CMREQ = connect_bcc(queryCMREQ)
[Mon Jul 02 13:51:23.148718 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] File "/var/www/flask-prod/flaskprod.py", line 86, in connect_bcc
[Mon Jul 02 13:51:23.148721 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] connection = cx_Oracle.connect(bccConnectionString)
[Mon Jul 02 13:51:23.148725 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212] cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help
[Mon Jul 02 13:51:23.148750 2018] [wsgi:error] [pid 18200] [remote 1.1.1.1: 1212]
P.S Все работает нормально на сервере фляги. Там нет проблем. Я добавляю еще немного информации ниже.
Это мой конфигурационный файл:
WSGIPassAuthorization On
WSGIScriptAlias /flaskprod /var/www/flask-prod/flaskprod.wsgi
WSGIDaemonProcess flaskprod user=cld group=users processes=5 threads=5 maximum-requests=1000 umask=0007
WSGIProcessGroup flaskprod
WSGISocketPrefix /var/run/wsgi
<Directory /var/www/flask-prod/>
Order allow,deny
Allow from all
</Directory>
Фрагмент кода моего питона:
def connect_bcc(query):
connectionString = 'bla bla'
connection = cx_Oracle.connect(connectionString)
cursor = connection.cursor()
cursor.execute(query)
return cursor.fetchall()
cursor.close()
connection.close()
@app.route('/requestbots', methods=['GET','POST'])
def get_cms_requested_for_approval():
if request.method == "POST":
queryCMREQFORAPPRVL = "SELECT * FROM....."
CMREQ = connect_bcc(queryCMREQ)
print (CM)
return json.dumps({'CM': CM})
Фрагмент кода js:
function getResult() {
$.ajax({
type: "POST",
url: $SCRIPT_ROOT + "/requestbots".....bla bla
})
}