'Cloudinary: Failed to establish a new connection: [Errno 111]

I am trying to upload a file with Python -not Django- across Cloudinary API but I am getting "Failed to establish a new connection: [Errno 111]". I am executing this script in PythonAnywhere.

This is my code:

import cloudinary
from cloudinary.uploader import upload
from cloudinary.utils import cloudinary_url

cloudinary.config(
  cloud_name = "name",
  api_key = "API_KEY",
  api_secret = "API_SECURE",
  secure = True
)

upload("BookCoverTest.jpg")

And the error I am getting is this one:

Traceback (most recent call last):
  File "/home/gcancino/notionBooks.py", line 148, in <module>
    queryWithFilter()
  File "/home/gcancino/notionBooks.py", line 71, in queryWithFilter
    getBookDataFromAPI(namee, pID)
  File "/home/gcancino/notionBooks.py", line 93, in getBookDataFromAPI
    upload("RitesofLucifer.jpg")
Traceback (most recent call last):
  File "/home/gcancino/.local/lib/python3.9/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/home/gcancino/.local/lib/python3.9/site-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/home/gcancino/.local/lib/python3.9/site-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/gcancino/.local/lib/python3.9/site-packages/cloudinary/uploader.py", line 534, in call_api
    response = _http.request("POST", api_url, param_list, headers, **kw)
  File "/home/gcancino/.local/lib/python3.9/site-packages/urllib3/request.py", line 78, in request
    return self.request_encode_body(
  File "/home/gcancino/.local/lib/python3.9/site-packages/urllib3/request.py", line 170, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "/home/gcancino/.local/lib/python3.9/site-packages/urllib3/poolmanager.py", line 375, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/home/gcancino/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 813, in urlopen
    return self.urlopen(
  File "/home/gcancino/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 813, in urlopen
    return self.urlopen(
  File "/home/gcancino/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 813, in urlopen
    return self.urlopen(
  File "/home/gcancino/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "/home/gcancino/.local/lib/python3.9/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: TCPKeepAliveHTTPSConnectionPool(host='api.cloudinary.com', port=443): Max retries exceeded with url: /v1_1/sampl
e/image/upload (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f7eb1283280>: Failed to establish a new connection:  [Errno 111] Connection refused'))

I have tried as well to configure this but don't know what to put in proxy (execute that code in the bash console of PythonAnywhere)

export CLOUDINARY_URL=cloudinary://API_KEY:API_SECRET@DB?api_proxy=DONTKNOWWHATTOPUTHERE


Solution 1:[1]

If you're using a free account on PythonAnyhwere, you have a restricted internet access to whitelisted domains, see whitelist. If the endpoint you're trying connect to is a public API, you can request a whitelist addition by contacting PA stuff and providing links to official docuementation of the given API endpoint.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 caseneuve