hi guys,
im a newbie to python.
watched some tutorial videos and just finished my first small project
i wrote the following codes to check the government website for the lowest petrol prices and when the keyword has been found, i will receive an email.
import requests
from bs4 import BeautifulSoup
import smtplib
def checkprice():
url = "https://www.accc.gov.au/consumers/petrol-diesel-lpg/petrol-price-cycles"
headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15"}
page = requests.get(url).text
soup = BeautifulSoup(page, 'html.parser')
obj = soup.find(id = "petrol-prices-in-melbourne")
next1 = obj.find_next("li").text
if "lowest" in next1:
send_mail()
*The above codings are working well in Pycharm, while trying to run on pythonanywhere, i got below error messages*.
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 594, in urlopen
self._prepare_proxy(conn)
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 805, in _prepare_proxy
conn.connect()
File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 308, in connect
self._tunnel()
File "/usr/lib/python3.8/http/client.py", line 898, in _tunnel
raise OSError("Tunnel connection failed: %d %s" % (code,
OSError: Tunnel connection failed: 403 Forbidden
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 637, in urlopen
retries = retries.increment(method, url, error=e, _pool=self,
File "/usr/lib/python3.8/site-packages/urllib3/util/retry.py", line 399, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.accc.gov.au', port=443): Max retries exceeded with url: /consumers/petrol-d
iesel-lpg/petrol-price-cycles (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/jaymeiqian/checkprice", line 12, in <module>
page = requests.get(url).text
File "/usr/lib/python3.8/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/usr/lib/python3.8/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 510, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.accc.gov.au', port=443): Max retries exceeded with url: /consumers/petrol-die
sel-lpg/petrol-price-cycles (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))
I googled this error and found a couple of solutions, but nothing works for me. it looks like something wrong with requests modules.
https://stackoverflow.com/questions/23013220/max-retries-exceeded-with-url-in-requests
the modules have been installed as per https://help.pythonanywhere.com/pages/InstallingNewModules
Can someone here please help with me with the error message?
Thanks heaps.