Forums

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.sendinblue.com', port=443): Max retries exceeded with url:

Hello, I am trying to use the SendinBlue API but I am keep getting an error. I have ran the code directly on my computer as a server and it works, so I'm not quite sure what's going wrong.

I am using this class:

from __future__ import print_function
import sib_api_v3_sdk
from sib_api_v3_sdk.rest import ApiException
from pprint import pprint
from constants import api_key

def SubToNewsletter(email):

  configuration = sib_api_v3_sdk.Configuration()
  configuration.api_key['api-key'] = api_key

  api_instance = sib_api_v3_sdk.ContactsApi(sib_api_v3_sdk.ApiClient(configuration))
  create_contact = sib_api_v3_sdk.CreateContact(email=email, list_ids=[5])

  try:
      api_response = api_instance.create_contact(create_contact)
      print(api_response)
      confirmEmail(email)
  except ApiException as e:
      print("Exception when calling ContactsApi->create_contact: %s\n" % e)

def confirmEmail(email):

    configuration = sib_api_v3_sdk.Configuration()
    configuration.api_key['api-key'] = api_key

    api_instance = sib_api_v3_sdk.TransactionalEmailsApi(sib_api_v3_sdk.ApiClient(configuration))
    subject = "Welcome to wsAlpha!"
    template_id = 26
    sender = {"name":"wsAlpha","email":"wsalpha.newsletter@gmail.com"}
    to = [{"email":email}]
    reply_to = {"email":"wsalpha.newsletter@gmail.com","name":"wsAlpha"}
    send_smtp_email = sib_api_v3_sdk.SendSmtpEmail(to=to, template_id=template_id, sender=sender, subject=subject, reply_to=reply_to)

    try:
        api_response = api_instance.send_transac_email(send_smtp_email)
        print(api_response)
    except ApiException as e:
        print("Exception when calling SMTPApi->send_transac_email: %s\n" % e)

This is the error I get:

2022-09-27 13:26:30,569: Exception on /subscribe [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable
**NO MATCH**
During handling of the above exception, another exception occurred:
**NO MATCH**
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1040, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 358, in connect
    self.sock = conn = self._new_conn()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fd6aae0b400>: Failed to establish a new connection: [Errno 101] Network is unreachable
**NO MATCH**
During handling of the above exception, another exception occurred:
**NO MATCH**
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/wsAlpha/mysite/wsAlpha.py", line 17, in subscribe
    newSubNL.SubToNewsletter(email)
  File "/home/wsAlpha/mysite/newSubNL.py", line 16, in SubToNewsletter
    api_response = api_instance.create_contact(create_contact)
  File "/home/wsAlpha/.local/lib/python3.10/site-packages/sib_api_v3_sdk/api/contacts_api.py", line 272, in create_contact
    (data) = self.create_contact_with_http_info(create_contact, **kwargs)  # noqa: E501
  File "/home/wsAlpha/.local/lib/python3.10/site-packages/sib_api_v3_sdk/api/contacts_api.py", line 335, in create_contact_with_http_info
    return self.api_client.call_api(
  File "/home/wsAlpha/.local/lib/python3.10/site-packages/sib_api_v3_sdk/api_client.py", line 329, in call_api
    return self.__call_api(resource_path, method,
  File "/home/wsAlpha/.local/lib/python3.10/site-packages/sib_api_v3_sdk/api_client.py", line 161, in __call_api
    response_data = self.request(
  File "/home/wsAlpha/.local/lib/python3.10/site-packages/sib_api_v3_sdk/api_client.py", line 371, in request
    return self.rest_client.POST(url,
  File "/home/wsAlpha/.local/lib/python3.10/site-packages/sib_api_v3_sdk/rest.py", line 269, in POST
    return self.request("POST", url,
  File "/home/wsAlpha/.local/lib/python3.10/site-packages/sib_api_v3_sdk/rest.py", line 162, in request
    r = self.pool_manager.request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/request.py", line 78, in request
    return self.request_encode_body(
  File "/usr/local/lib/python3.10/site-packages/urllib3/request.py", line 170, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "/usr/local/lib/python3.10/site-packages/urllib3/poolmanager.py", line 376, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 813, in urlopen
    return self.urlopen(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 813, in urlopen
    return self.urlopen(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 813, in urlopen
    return self.urlopen(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.sendinblue.com', port=443): Max retries exceeded with url: /v3/contacts (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fd6aae0b400>: Failed to establish a new connection: [Errno 101] Network is unreachable'))

Any help would be greatly appreciated.

Thanks!

You need to configure the library that you're using to use the proxy. Check the documentation of the library to find out how and the details you need are here: https://help.pythonanywhere.com/pages/403ForbiddenError/