Python helpers

proxy_request & proxy_session

Call APIs that only accept allowlisted IP addresses, from Octocom's fixed outbound IP.

Some APIs only accept requests from allowlisted IP addresses, or block generic cloud IP ranges. These helpers route your request through Octocom's HTTP proxy, so the API always sees the same fixed outbound IP. The third party allowlists it once, and every Python automation can reach the API.

proxy_request(method: str, url: str, **kwargs) -> requests.Response
proxy_session(headers: dict = None) -> requests.Session

proxy_request makes a single request. proxy_session returns a pre-configured requests.Session for several calls to the same API: auth headers set once, connection reuse, and every request routed through the proxy.

These helpers are the supported fixed-IP interface. Do not embed proxy URLs or credentials, or set session.proxies manually: in Octocom's Python runtime, manual HTTP proxy settings raise ProxyError. Replace such setup with proxy_session() and keep your destination headers and per-request timeouts. This also applies when you restore an older version of an automation.

Where it works: every Python automation, including custom actions, condition providers, event handlers, recurring jobs, HTTP endpoints and sidebar widgets. Product-sync parsers have their own equivalent, fetch_via_proxy, which uses the same outbound IP.


Why use the proxy

By default, outbound requests from your Python code leave through a shared cloud IP that isn't guaranteed to stay the same. That's fine for most APIs, but breaks down when:

  • The API requires you to register an allowlisted IP (common for order-management, ERP, and payment systems)
  • The API blocks well-known cloud IP ranges, returning 403, 429, or connection timeouts on requests that work elsewhere

Routing through the proxy solves both: the third party sees one fixed Octocom IP. The outbound IP is 74.242.171.127; add it to your provider's allowlist. If it ever changes, Octocom notifies affected customers in advance.


proxy_request

proxy_request(method: str, url: str, **kwargs) -> requests.Response
NameTypeDescription
methodstrHTTP method: "GET", "POST", "PUT", "DELETE" and so on
urlstrAbsolute URL to call.
**kwargsanyAnything requests.request() accepts: headers, params, json, data, timeout and so on

Returns a requests.Response. The timeout defaults to 30 seconds; pass timeout=... to change it. Like requests itself, it does not raise on non-2xx responses: check response.ok or call response.raise_for_status().

def execute_action(context):
    order_id = context["args"]["orderId"]

    response = proxy_request(
        "GET",
        f"https://api.example.com/orders/{order_id}",
        headers={"Authorization": "Bearer <token>"},
    )
    if not response.ok:
        return {"error": f"Order lookup failed ({response.status_code})."}

    order = response.json()
    return {"orderId": order["id"], "status": order["status"]}

proxy_session

proxy_session(headers: dict = None) -> requests.Session
NameTypeDescription
headersdict or NoneDefault headers applied to every request the session makes. Put your Authorization or API-key headers here.

Returns a requests.Session with the proxy pre-configured. Use it when your code makes multiple calls to the same API:

def execute_action(context):
    email = context["args"]["email"]

    session = proxy_session(headers={
        "X-Api-Key": "<api-key>",
        "Content-Type": "application/json",
    })

    orders = session.get(
        "https://api.example.com/orders",
        params={"email": email},
        timeout=30,
    ).json()

    if not orders:
        return f"No orders found for {email}."

    latest = orders[0]
    session.put(
        f"https://api.example.com/orders/{latest['id']}/notes",
        json={"note": "[Octocom] Customer contacted support"},
        timeout=30,
    )

    return {"orderId": latest["id"], "status": latest["status"]}

Unlike proxy_request, the session does not apply a default timeout: pass timeout= on each call.


When to use it

Default to plain requests. The proxy is an extra hop; only route through it when the target API allowlists by IP or you've seen it block the default outbound IP (403, 429 or timeouts on URLs that work in a browser). Once an API is behind an IP allowlist, use proxy_session for all calls to it: a mix of proxied and direct calls fails intermittently.


On this page