I'm trying to run the Python script that I wrote for scraping a particular website, and then I need to get notified with an email when the price reaches a specific number, for that matter I used PythonAnywhere, but when I run my script in the console, I get the following error, even though it runs normally on Pycharm:
requests.exceptions.ProxyError: HTTPSConnectionPool(host='order.badinanshipping.com', port=443): Max retries exceeded with url: /profile/b763bd64-
1064-426a-b949-d8e5232919ee/invoice (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))
code:
from bs4 import BeautifulSoup
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
import smtplib
url = "https://order.badinanshipping.com/profile/b763bd64-1064-426a-b949-d8e5232919ee/invoice"
session = requests.Session()
retry = Retry(connect=3, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
response = session.get(url)
badini_page = response.text
def send_email(email, password, message):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(email, password)
server.sendmail(email, email, message)
server.quit()
soup = BeautifulSoup(badini_page, "html.parser")
price = soup.find(class_="my-box2")
net_price = int(price.getText().split("IQD")[0])
if net_price > 75000:
send_email("myEmail", "myPassword",
"\n\n*******\n\n Go pick them up, now! \n\n*******\n\n")
CodePudding user response:
When using pythonanywhere free trail you can only send request to their Whitelisted site but their paid accounts have unrestricted access.
If you are using their free version then make sure you are sending request from their whitelisted site. Click here to see their all whitelisted site
You can use replit. Normally I use replit as for testing and run my code. They have both free and paid version but they haven't any limitation for sending request like pythonanywhere. There are lot of company providing cloud service for running your code or app on their hosting. such as digitalocean, aws. digitalocean is very beginner friendly.
You can deploy your app or code directly from git on digitalocean. If you don't want to take any headache for deploying app and server configuration then go with digitalocean otherwise I will suggest aws.
One of the biggest reason why I am suggesting aws because it's very cost effective and secure. Aws is market leader for cloud computing and you don't need to be think about their security.
You will get aws one year free tire period. I think one year free tire is great for learning and exploring different kind of aws service.
You must have some technical knowledge for deploying your app on aws. There are lot of tutorial on google and youtube where you can learn.
