Do you have a module of your own named "requests" that is being confused,
somehow, with the installed package?
Or might you be importing something "as requests"?

On Thu, Sep 28, 2017 at 12:02 PM, Chris Barton <
[email protected]> wrote:

> Hello,
>
> 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.
>
> *Python traceback*:
> [Fri Sep 22 16:35:49.378817 2017] [wsgi:error] [pid 1708:tid
> 139626802534144] [remote 10.6.70.171:50515] [2017-09-22 16:35:49,377]
> ERROR in app: Exception on /conference [POST]
> [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.378918 2017] [wsgi:error] [pid 1708:tid
> 139626802534144] [remote 10.6.70.171:50515]     slack(message + '\\n' +
> traceback, 'https://hooks.slack.com/services/<URL REMOVED>')
> [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'
>
>
> *Apache startup message showing mod_wsgi compiled for Python3.6*:
> [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
>
> *Python packages installed in the virtualenv*:
> (venv) root@ub50368:/var/www/sites/api# pip list
> certifi (2017.7.27.1)
> chardet (3.0.4)
> click (6.7)
> configparser (3.5.0)
> Flask (0.12.2)
> Flask-Cors (3.0.3)
> Flask-MySQL (1.4.0)
> idna (2.6)
> itsdangerous (0.24)
> Jinja2 (2.9.6)
> MarkupSafe (1.0)
> pip (9.0.1)
> PyMySQL (0.7.11)
> pytz (2017.2)
> requests (2.18.4)
> setuptools (36.5.0)
> six (1.10.0)
> urllib3 (1.22)
> Werkzeug (0.12.2)
> wheel (0.30.0)
>
> *Globally installed Python packages*:
> root@ub50368:/var/www/sites/api# pip3.6 list
> pip (9.0.1)
> setuptools (28.8.0)
> virtualenv (15.1.0)
>
> *WSGI Directives from Apache2 configuration*:
> WSGIDaemonProcess rest_api_v1 user=api group=api home=/var/www/sites/api
> python-home=/var/www/sites/api/venv
> WSGIProcessGroup rest_api_v1
> #WSGIApplicationGroup %{GLOBAL}
> WSGIScriptAlias / /var/www/sites/api/start.wsgi
>
> *Things we've tried*:
>
>    - Installing requests (& all pip packages) globally and disabling the
>    python-home parameter
>    - Rebuilding the virtualenv
>    - Installing requests directly from git/source
>    - Using the activate_this.py - http://flask.pocoo.org/docs/
>    0.12/deploying/mod_wsgi/#working-with-virtual-environments
>    
> <http://flask.pocoo.org/docs/0.12/deploying/mod_wsgi/#working-with-virtual-environments>
>    - Embedding the requests source directly in the Flask app
>
>
> Does anyone have any idea of what could be going wrong, or how to dive
> deeper into the problem?
>
> Thanks,
>
> Chris
>
> --
> You received this message because you are subscribed to the Google Groups
> "modwsgi" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/modwsgi.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to