Forums

Request to playtomic.io

Hi, my script send a request to the site playtomic.io with requests library but I receive a 'OSError: Tunnel connection failed: 403 Forbidden'. From my pc everything work well. I have an hacker accounts. What's I'm wrong?

Thanks Gianluca

That sounds strange -- from a paid account, your code should not be trying to tunnel. What is the exact code you're using (with any passwords hidden, of course)? And what is the full error message?

This is the funcion :

def list_tenants(file_name):
    url = "https://playtomic.io/api/v1/tenants"
    querystring = querystring = {"user_id":"me","playtomic_status":"ACTIVE","with_properties":"ALLOWS_CASH_PAYMENT","coordinate":"44.647128,10.925227","sport_id":"PADEL","radius":"50000","size":"40"}
    headers = {
        'cache-control': "no-cache",
        }
    response = requests.request("GET", url, headers=headers, params=querystring)
    with open(file_name, "w", encoding='utf-8') as file:
        file.write(response.text)
    return response.json()

Error:

13:33 ~/BusyPacelCourts $ python3.9 scraper.py                                                                                                                         
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 696, in urlopen
    self._prepare_proxy(conn)
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 964, in _prepare_proxy
    conn.connect()
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 366, in connect
    self._tunnel()
  File "/usr/local/lib/python3.9/http/client.py", line 903, in _tunnel
    raise OSError(f"Tunnel connection failed: {code} {message.strip()}")
OSError: Tunnel connection failed: 403 Forbidden
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 573, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='playtomic.io', port=443): Max retries exceeded with url: /api/v1/tenants?user_id=me&playtomic_status=ACTIVE
&with_properties=ALLOWS_CASH_PAYMENT&coordinate=44.647128%2C10.925227&sport_id=PADEL&radius=50000&size=40 (Caused by ProxyError('Cannot connect to proxy.', OSError('Tu
nnel connection failed: 403 Forbidden')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/dallarg/BusyPacelCourts/scraper.py", line 33, in <module>
    data = list_tenants(tenants_file)
  File "/home/dallarg/BusyPacelCourts/scraper.py", line 17, in list_tenants
    response = requests.request("GET", url, headers=headers, params=querystring)
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 510, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='playtomic.io', port=443): Max retries exceeded with url: /api/v1/tenants?user_id=me&playtomic_status=ACTIVE&w
ith_properties=ALLOWS_CASH_PAYMENT&coordinate=44.647128%2C10.925227&sport_id=PADEL&radius=50000&size=40 (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunn
el connection failed: 403 Forbidden')))
13:35 ~/BusyPacelCourts $ curl -X GET \
>   'https://playtomic.io/api/v1/tenants?user_id=me&playtomic_status=ACTIVE&with_properties=ALLOWS_CASH_PAYMENT&coordinate=44.647128%2C10.925227&sport_id=PADEL&radius=
50000&size=40' \
>   -H 'cache-control: no-cache' \
>   -H 'postman-token: d96ea613-0cb7-7e40-9981-b8f6e7473c9b'
curl: (56) Received HTTP code 403 from proxy after CONNECT

[edit by admin: formatting]

If I send by console a cUrl command same error.

curl -X GET   'https://playtomic.io/api/v1/tenants?user_id=me&playtomic_status=ACTIVE&with_properties=ALLOWS_CASH_PAYMENT&coordinate=44.64712
8%2C10.925227&sport_id=PADEL&radius=50000&size=40'   -H 'cache-control: no-cache'   -H 'postman-token: d96ea613-0cb7-7e40-9981-b8f6e7473c9b'
**curl: (56) Received HTTP code 403 from proxy after CONNECT**

[edit by admin: formatting]

What do you see if you run the Bash command

echo $https_proxy

...? If it's not just a blank line, but instead something including proxy.server, then try starting a new console and running the code there -- that would indicate that the console you are running in has kept the old free account settings, but a new one will fix that.

you are right. Thanks it works

No problem, glad to help!