Faile d to establish a new connection: [Errno 111] in Python

Comments

6 comments

  • Avatar
    Wissam Khalili

    Hi Genaro,

    I've found this StackOverflow thread of what seems to be the exact issue you're describing -
    https://stackoverflow.com/questions/54217041/how-to-set-up-proxy-details-in-pythonanywhere-for-cloudinary

    Can you try upgrading the urllib3​ library and let me know if it helps?

    Another possible solution I found is setting the api_proxy​ attribute in the Cloudinary configuration object to http://proxy.server:3128

    CLOUDINARY = {
    'cloud_name': '',
    'api_key': '',
    'api_secret': '',
    'api_proxy': 'http://proxy.server:3128'
    }

    Can you try this solution as well?
    Thanks,

    Wissam

    0
    Comment actions Permalink
  • Avatar
    Genaro Cancino

    Hello, Wissam
    Thanks for your response.

    I tried to upgrade the lib in the server and put the proxy in the config with no result.Still getting the same error

    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/dorz1
    6tij/image/upload (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f7f7fac8b80>: Failed to establish a new connecti
    on: [Errno 111] Connection refused'))
    0
    Comment actions Permalink
  • Avatar
    Wissam Khalili

    Hi Genaro,

    I saw that it was resolved in the following thread:

    https://stackoverflow.com/questions/70153259/cloudinary-image-upload-errpr-in-django-python-while-hosted-in-pythonanywhere

    settings.py should be in lower caps.

    CLOUDINARY = {
          'cloud_name': 'CLOUD-NAME',  
          'api_key': 'xx',  
          'api_secret': 'xx',
          'api_proxy': 'http://proxy.server:3128'
    }

    This is what I found from the Pythoanywhere forum:

    https://help.pythonanywhere.com/pages/403ForbiddenError

    Regards,

    Wissam

    0
    Comment actions Permalink
  • Avatar
    Genaro Cancino

    Hey again, Wissam.

    The problem is that I am not using django. I am just using Python.
    So I put my config like this:
    cloudinary.config(
      cloud_name = xxxx",
      api_key = "xxxxxxxxxxxx",
      api_secret = "xxxxxxxxxxx",
      api_proxy = "http://proxy.server:3128"
    )

    0
    Comment actions Permalink
  • Avatar
    Thomas Gurung

    Hi Genaro,

    Just a quick update, I tested this myself on a PythonEverwhere instance (Free version) and I was able to replicate it. I'm still unsure what the reason is but right now it could be something to do with our SDK as making a direct call to our APIs were successful for me. The instance should already be configured to use their Proxy from initial investigations.

    I will look into it more but do let still let us know the PythonEverywhere plan you are on. For now, a workaround is to build the request yourself.

    More on manual generation here. Let us know if you have any questions in the meantime.

    Thanks,
    Thomas

    0
    Comment actions Permalink
  • Avatar
    Thomas Gurung

    Hi Genaro,

    Apologies for the delay, so I've investigated this a bit  and can you instead create an environment variable like so before running the script:

    export CLOUDINARY_URL=cloudinary://API_KEY:API_SECRET@cloud_name?api_proxy=http://proxy.server:3128

    You'll probably want to save that to your .bashrc file so it pre-loads every time and you don't have to manually set it.

    echo "export CLOUDINARY_URL=cloudinary://API_KEY:API_SECRET@cloud_name?api_proxy=http://proxy.server:3128" >> ~/.bashrc
    source ~/.bashrc

    If you prefer using cloudinary.config() then make sure to include it after "import cloudinary" module but before "import cloudinary.uploader" and "import cloudinary.api". So something like:

    import cloudinary
    cloudinary.config(
    cloud_name = "xxxx",
    api_key = "xxxxxxxxxxxx",
    api_secret = "xxxxxxxxxxx",
    api_proxy = "http://proxy.server:3128"
    )
    import cloudinary.uploader
    import cloudinary.api

    Please let me know how you get on.

    Thanks,
    Thomas

    0
    Comment actions Permalink

Please sign in to leave a comment.