using pymongo in Gunicorn

Running Ubunto 22, I installed pymongo, added import pymongo to .If I run using python3 no issues. If I sudo systemctl restart myproject, I get a 502 bad gateway error. Any clues? Thanks

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Site Moderator
Site Moderator badge
May 9, 2023

Hey @basilcabrera,

Check your logs, what does Nginx say other than 502 bad gateway? Additionally, check your application’s log, do you see anything there? it’s important to have access to logs. By default, Gunicorn logs errors and warnings. You can configure Gunicorn logging to get more information, including access logs.

Here are a few steps to enable and manage Gunicorn logging:

Update your gunicorn configuration:

In your gunicorn service file /etc/systemd/system/gunicorn.service, update the ExecStart line to include log file paths for access and error logs. Replace the following line:

--access-logfile - \


--access-logfile /path/to/your/access.log \
--error-logfile /path/to/your/error.log \
--log-level info \

Make sure to replace /path/to/your/access.log and /path/to/your/error.log with the desired paths for your log files.

The --log-level flag can be set to different values, depending on the level of detail you want in your logs:

  • debug: Detailed logs including all messages, useful for debugging.
  • info: Default logging level, includes error and informational messages.
  • warning: Only logs warning and error messages.
  • error: Logs only error messages.
  • critical: Logs only critical error messages.

After updating the configuration, restart the gunicorn service for the changes to take effect:

sudo systemctl daemon-reload 
sudo systemctl restart gunicorn

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel