Forums

OSError: Tunnel connection failed: 403 Forbidden

When I run the script, error messages like below occurs. And this script runs fine on Mac, Windows, and even other cloud platform (Ubuntu).

Could you help me with that?

Traceback (most recent call last):
  File "/home/macivj/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 594, in urlopen
    self._prepare_proxy(conn)
  File "/home/macivj/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 805, in _prepare_proxy
    conn.connect()
  File "/home/macivj/.local/lib/python3.9/site-packages/urllib3/connection.py", line 308, 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 "/home/macivj/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 637, in urlopen
    retries = retries.increment(method, url, error=e, _pool=self,
  File "/home/macivj/.local/lib/python3.9/site-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.kebhana.com', port=443): Max retries exceeded with url: /cms/rate/wpfxd651_07i_01.do (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/macivj/dh.py", line 304, in <module>
    dollar()
  File "/home/macivj/dh.py", line 36, in dollar
    response = requests.post(url=url5, headers=headers, data=data,allow_redirects=True)
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 119, in post
    return request('post', url, data=data, json=json, **kwargs)
  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='www.kebhana.com', port=443): Max retries exceeded with url: /cms/rate/wpfxd651_07i_01.do (Caused by ProxyE
rror('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))

[edit by admin: formatting]

Free accounts on PythonAnywhere can only access the list of official public APIs on our whitelist. If the site that you're trying to connect to is an official API, we may be able to add it -- see this help page.