Skip to content

Cloudflare blocks API key creation (403) with py_clob_client_v2 #41

@numan0x618

Description

@numan0x618

When attempting to create/derive API L2 keys using py_clob_client_v2, the process fails:

  1. Cloudflare 403 block on /auth/api-key (full HTML "Attention Required" page)
  2. Then 400 error on /auth/derive-api-key: {"error":"Could not derive api key!"}

The /api/geoblock endpoint works correctly, returning "blocked":false.
Info from https://ipapi.is/:
"is_bogon": false,
"is_mobile": false,
"is_satellite": false,
"is_crawler": false,
"is_datacenter": false,
"is_tor": false,
"is_proxy": false,
"is_vpn": false,
"is_abuser": false
The issue appears to be Cloudflare blocking the /auth/api-key request. Please investigate Cloudflare compatibility in py_clob_client_v2.

Full error log:

[py_clob_client_v2] request error status=403 url=https://clob.polymarket.com/auth/api-key body=<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en-US"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en-US"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]-->
<head>
<title>Attention Required! | Cloudflare</title>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="stylesheet" id="cf_styles-css" href="/cdn-cgi/styles/cf.errors.css" />
<!--[if lt IE 9]><link rel="stylesheet" id='cf_styles-ie-css' href="/cdn-cgi/styles/cf.errors.ie.css" /><![endif]-->
<style>body{margin:0;padding:0}</style>


<!--[if gte IE 10]><!-->
<script>
  if (!navigator.cookieEnabled) {
    window.addEventListener('DOMContentLoaded', function () {
      var cookieEl = document.getElementById('cookie-alert');
      cookieEl.style.display = 'block';
    })
  }
</script>
<!--<![endif]-->

</head>
<body>
  <div id="cf-wrapper">
    <div class="cf-alert cf-alert-error cf-cookie-error" id="cookie-alert" data-translate="enable_cookies">Please enable cookies.</div>
    <div id="cf-error-details" class="cf-error-details-wrapper">
      <div class="cf-wrapper cf-header cf-error-overview">
        <h1 data-translate="block_headline">Sorry, you have been blocked</h1>
... [Cloudflare HTML content] ...
</body>
</html>

[py_clob_client_v2] request error status=400 url=https://clob.polymarket.com/auth/derive-api-key body={"error":"Could not derive api key!"}

Traceback (most recent call last):
  File "L2.py", line 87, in <module>
    creds = client.create_or_derive_api_key()
  File "py_clob_client_v2\client.py", line 483, in create_or_derive_api_key
    return self.derive_api_key(nonce=nonce)
  File "py_clob_client_v2\client.py", line 469, in derive_api_key
    resp = self._get(f"{self.host}{DERIVE_API_KEY}", headers=headers)
  File "py_clob_client_v2\client.py", line 200, in _get
    return get(endpoint, headers=headers, params=params)
  File "py_clob_client_v2\http_helpers\helpers.py", line 92, in get
    return request(endpoint, GET, headers, data, params)
  File "py_clob_client_v2\http_helpers\helpers.py", line 78, in request
    raise PolyApiException(resp)
py_clob_client_v2.exceptions.PolyApiException: PolyApiException[status_code=400, error_message={'error': 'Could not derive api key!'}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions