Forums

ProxyError('Connot connect to proxy.', OSError('Tunne | connection failed: 403 forbidden')

I am trying to run some python code, which uses request and the currents API for getting news articles. I know my code works locally on my own machine, but I'm getting a 403 error as it can't connect to that API (see the error below). I was wondering if there was some way that I could get it to connect and actually get data from the API.

I have recently requested that the currentsAPI to be added to the allowlist which it has been added recently since writing this. I don't know if I have to wait so long for it to update the allowlist accordingly but I've waited over an hour and still nothing. Although I haven't shared the code I'm trying to run (just to reduce clutter), I am willing to share it if necessary.

Traceback (most recent call last):
  File "/home/jamster/collection/test.py", line 96, in <module>
    news_data = News()
  File "/home/jamster/collection/test.py", line 41, in __init__
    self.currents = self.collect_news_data(categories)
  File "/home/jamster/collection/test.py", line 90, in collect_news_data
    news = self.fetch_news(category=category, start_date=date_str, end_date=date_str)
  File "/home/jamster/collection/test.py", line 55, in fetch_news
    response = requests.get(url, params=params)
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 559, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='api.currentsapi.services', port=443): Max retries exceeded with url: /v1/search?apiKey=[APIKEY Blanked out]&language=en&category=regional&start_date=2024-10-17&end_date=2024-10-17 (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunne
l connection failed: 403 Forbidden')))

[edit by admin: formatting]

I don't see api.currentsapi.services on our allowlist, just currentsapi.services. The hostname has to exactly match what is on the request, so if you need to access the one with api. at the start, that's what you'll need to get added to the allowlist.

I see... alright. I requested for currentsAPI, I clearly just misunderstood a few things, that might be where I'm goign wrong then. I'll try requesting for the correct service API then, I never noticed that it wasn't the right one.

I'm not new to pythonanywhere but didn't know it went into so much depth with things, including a whitelist/allowlist (which makes sense for security reasons).

EDIT: Okay it works now, my bad for not relising I requested the wrong service of currents

Glad you got it working