1

I'm developing a Django application that uses Cloudinary for image storage. When running the project locally, everything works fine, and images upload successfully.

However, when I deploy the project on PythonAnywhere, I get the following error when trying to upload an image from the admin panel:

Unexpected error - MaxRetryError("TCPKeepAliveHTTPSConnectionPool(host='api.cloudinary.com', port=443): Max retries exceeded with url: /v1_1/di6geozk1/image/upload (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x748d7df0b520>: Failed to establish a new connection: [Errno 111] Connection refused'))")

Configuration in settings.py:

CLOUDINARY_STORAGE = {
    'CLOUD_NAME': env('CLOUDINARY_STORAGE_CLOUD_NAME', default=''),
    'API_KEY': env('CLOUDINARY_STORAGE_API_KEY', default=''),
    'API_SECRET': env('CLOUDINARY_STORAGE_API_SECRET', default=''),
    'SECURE': True,
    'API_PROXY': 'http://proxy.server:3128'
}

Things I've already checked:

  • The credentials (CLOUD_NAME, API_KEY, API_SECRET) are correctly set.
  • In my local environment, images upload successfully to Cloudinary.
  • In PythonAnywhere, the connection is refused.
  • I tried removing the 'API_PROXY' setting, but the error persists.
2
  • This question is similar to: Uploaded an image got [Error 111] using Cloudinary on Pythonanywhere. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Feb 23 at 0:20
  • If you are a free user your outbound internet access is limited to a whitelist. see this Commented Feb 24 at 8:40

1 Answer 1

1

For security purposes, PythonAnywhere's free accounts' internet access goes via a proxy "allowlist"; they can only access sites that are on that list. Cloudinary is on that list (see the list of sites currently allowed.)

The [Errno 111] Connection refused error you're getting suggests that either Cloudinary doesn't support using a proxy, or that it needs to be configured to use a proxy. Have a look at their docs to determine which it is and consider raising an issue with the project about proxy support.

Also review your Cloudinary configuration to ensure that it includes the correct proxy settings. Do note that paying users don't have this limitation. See https://help.pythonanywhere.com/pages/403ForbiddenError/#proxy-details

NOTE: You can let PythonAnywhere serve media files for you. To do that:

  • in your settings.py set MEDIA_ROOT to some path (like /home/yourusername/yourproject/media) and MEDIA_URL to /media/ (or whatever URL you want)

  • on a web app tab scroll down to Static files section and make sure there is a row with your MEDIA_URL and the path you set for MEDIA_ROOT.

  • restarting your web app and all user-uploaded content will be correctly served.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.