xinitrc-dev / randomfox.ca

http://randomfox.ca/
Other
90 stars 19 forks source link

403 Forbidden trying to fetch the API on Python Anywhere #12

Closed aitorres closed 4 years ago

aitorres commented 4 years ago

Hello! First of all, thanks for developing this cute API!

I'm trying to use the randomfox API to get an image of a fox for a small, toy Telegram bot I'm developing. On my local development environment, I have no problem using the API, either through curl on my terminal or using the requests python package.

However, trying to fetch the API on Python Anywhere (to deploy the bot) gives me a 403 response:

22:50 ~/dogpicsbot (master)$ curl https://randomfox.ca/floof/
curl: (56) Received HTTP code 403 from proxy after CONNECT

22:50 ~/dogpicsbot (master)$ curl -I https://randomfox.ca/floof/
HTTP/1.1 403 Forbidden
Server: squid/3.5.12
Mime-Version: 1.0
Date: Sun, 23 Aug 2020 22:50:52 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 811
X-Squid-Error: ERR_ACCESS_DENIED 0
X-Cache: MISS from green-liveproxy1
X-Cache-Lookup: NONE from green-liveproxy1:3128
Via: 1.1 green-liveproxy1 (squid/3.5.12)
Connection: keep-alive
curl: (56) Received HTTP code 403 from proxy after CONNECT

Using python's requests module:

>>> import requests
>>> requests.get(url="https://randomfox.ca/floof/")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 507, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='randomfox.ca', port=443): Max retries exceeded with url: /floof/ (Caused by ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 403 Forbidden',)))

(this particular test was done on python2, but python3 renders the same result, I also tried with http instead of https and it's the same)

Do you have any idea of why this happens?

xinitrc-dev commented 4 years ago

Hmm, this could be either cloudflare, or my hosting provider auto blocking python anywhere's IP. However, i've also stumbled upon this page, which suggests you can only access whitelisted websites if you have a free account with Python Anywhere. https://help.pythonanywhere.com/pages/403ForbiddenError/ Please, make sure you dont have a free account, and you can try giving me an IP address from which I should antisipate requests, so i can explicitely whitelist it.

aitorres commented 4 years ago

Hello! Thanks for reaching out so fast. I'm sorry, I should have checked the PythonAnywhere help in more detail.

I talked to PA's support team, and they have added randomfox.ca to their allowed domains. Just wanted to let you know!

xinitrc-dev commented 4 years ago

Well hot diddly darn, I have just put that on my to-do list. Thanks! 🦊