I've been working on the deployment of a Flask application using mod_wsgi4.5.18 (compiled against Python3.6.1) and have been encountering issues with the requests library that only seem to manifest when the Flask app is run from behind Apache & mod_wsgi. When the app is invoked from the virtualenv python interpreter it works flawlessly.
The problem occurs in areas where we are attempting to use the requests library to make a call to external APIs (BlueJeans & Slack) during the handling of a request to our Flask app.
Here are some pieces of our current configuration. We've been puzzled by this for the past two weeks and do not seem to be getting any closer to a solution. At this point the development team is asking to look at other options such as Nginx & Gunicorn.
[Fri Sep 22 16:35:49.378844 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] Traceback (most recent call last):
[Fri Sep 22 16:35:49.378847 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] File "/var/www/sites/api/rest_api_v1/util/bluejeans.py", line 13, in password_grant
[Fri Sep 22 16:35:49.378850 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] r =
requests.post(BASE_URL + '/oauth2/token?Password', json=json)
[Fri Sep 22 16:35:49.378852 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] AttributeError: module 'requests' has no attribute 'post'
[Fri Sep 22 16:35:49.378855 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515]
[Fri Sep 22 16:35:49.378857 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] During handling of the above exception, another exception occurred:
[Fri Sep 22 16:35:49.378859 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515]
[Fri Sep 22 16:35:49.378861 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] Traceback (most recent call last):
[Fri Sep 22 16:35:49.378863 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] File "/var/www/sites/api/venv/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
[Fri Sep 22 16:35:49.378866 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] response = self.full_dispatch_request()
[Fri Sep 22 16:35:49.378868 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] File "/var/www/sites/api/venv/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
[Fri Sep 22 16:35:49.378871 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] rv = self.handle_user_exception(e)
[Fri Sep 22 16:35:49.378873 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] File "/var/www/sites/api/venv/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
[Fri Sep 22 16:35:49.378875 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] return cors_after_request(app.make_response(f(*args, **kwargs)))
[Fri Sep 22 16:35:49.378877 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] File "/var/www/sites/api/venv/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
[Fri Sep 22 16:35:49.378880 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] reraise(exc_type, exc_value, tb)
[Fri Sep 22 16:35:49.378882 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] File "/var/www/sites/api/venv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
[Fri Sep 22 16:35:49.378884 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] raise value
[Fri Sep 22 16:35:49.378886 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] File "/var/www/sites/api/venv/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
[Fri Sep 22 16:35:49.378889 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] rv = self.dispatch_request()
[Fri Sep 22 16:35:49.378891 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] File "/var/www/sites/api/venv/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
[Fri Sep 22 16:35:49.378893 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] return self.view_functions[rule.endpoint](**req.view_args)
[Fri Sep 22 16:35:49.378895 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] File "/var/www/sites/api/rest_api_v1/endpoints/conference.py", line 11, in create_conference
[Fri Sep 22 16:35:49.378898 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] response, status = conference.create_conference(request.json)
[Fri Sep 22 16:35:49.378902 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] File "/var/www/sites/api/rest_api_v1/logic/conference.py", line 35, in create_conference
[Fri Sep 22 16:35:49.378904 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] userId, token = bjn_util.password_grant(bjn_config.USERNAME, bjn_config.PASSWORD)
[Fri Sep 22 16:35:49.378907 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] File "/var/www/sites/api/rest_api_v1/util/bluejeans.py", line 24, in password_grant
[Fri Sep 22 16:35:49.378909 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] logger.error(ex, application='Conference')
[Fri Sep 22 16:35:49.378911 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] File "/var/www/sites/api/rest_api_v1/util/logger.py", line 81, in error
[Fri Sep 22 16:35:49.378913 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] log(message, logType='error', application=application, traceback=traceback)
[Fri Sep 22 16:35:49.378916 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] File "/var/www/sites/api/rest_api_v1/util/logger.py", line 70, in log
[Fri Sep 22 16:35:49.378920 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] File "/var/www/sites/api/rest_api_v1/util/logger.py", line 20, in slack
[Fri Sep 22 16:35:49.378923 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] response =
requests.post(webhook_url, data=json.dumps(slack_data),
[Fri Sep 22 16:35:49.378926 2017] [wsgi:error] [pid 1708:tid 139626802534144] [remote
10.6.70.171:50515] AttributeError: module 'requests' has no attribute 'post'
[Wed Sep 27 16:13:25.690202 2017] [mpm_event:notice] [pid 63496:tid 139773643462528] AH00489: Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g mod_wsgi/4.5.18 Python/3.6 configured -- resuming normal operations
Does anyone have any idea of what could be going wrong, or how to dive deeper into the problem?