Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script has stopped working
#1
Hello

Can anyone tell me why my script has stopped working?
Error:
Last login: Wed Feb 22 17:10:02 on console Nicks-Mac-Mini:~ nickburrett$ python /Users/nickburrett/Sync/Nick\'s\ Backup/My\ Downloads/Python/Entsweb/Entsweb.py Traceback (most recent call last):  File "/Users/nickburrett/Sync/Nick's Backup/My Downloads/Python/Entsweb/Entsweb.py", line 67, in <module>    r = requests.get(config["url"])  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/api.py", line 70, in get    return request('get', url, params=params, **kwargs)  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/api.py", line 56, in request    return session.request(method=method, url=url, **kwargs)  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 488, in request    resp = self.send(prep, **send_kwargs)  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 609, in send    r = adapter.send(request, **kwargs)  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/adapters.py", line 497, in send    raise SSLError(e, request=request) requests.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:661) Nicks-Mac-Mini:~ nickburrett$
Reply
#2
It's definitely tough without seeing the script. From the tiny bit you've posted, I could guess that you're scraping a site and they're blocking you now.
Reply
#3
import requests
from lxml import html
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

def send_email(message_html, message_text):
    
    # Create message container - the correct MIME type is multipart/alternative.
    msg = MIMEMultipart('alternative')
    msg['Subject'] = config["email_subject"]
    msg['From'] = config["email_from"]
    msg['To'] = config["email_to"]
    
    # Record the MIME types of both parts - text/plain and text/html.
    part1 = MIMEText(message_text, 'plain')
    part2 = MIMEText(message_html, 'html')
    
    # Attach parts into message container.
    # According to RFC 2046, the last part of a multipart message, in this case
    # the HTML message, is best and preferred.
    msg.attach(part1)
    msg.attach(part2)
    
    # Send the message via local SMTP server.
    s = smtplib.SMTP( config["smpt_host"] + ":" + config["smtp_port"] )
    # sendmail function takes 3 arguments: sender's address, recipient's address
    # and message to send - here it is sent as one string.
    s.login(config["smtp_user"], config["smtp_password"])
    s.sendmail(config["email_from"], config["email_to"], msg.as_string())
    s.quit()

def format_html(job):
    job_html = """
    <div class="jobs-item" style="border: 1px solid rgb(204,204,204); width: 100%; margin-top: 20px;">
        <h3><a href="{0}">{1}</a></h3>
        <p class="location">Location:<strong>{2}</strong></p>
        <p>{3}<a href="{0}" class="next">Full Details</a></p>
    </div>
    """.format( job["url"], job["title"], job["location"], job["description"].encode('utf-8') )
    
    return job_html

def format_text(job):
    job_text = """
{1}
{2}
{3}
{0}

""".format( job["url"], job["title"], job["location"], job["description"].encode('utf-8') )
    
    return job_text

config = {
    
    "url" : "https://www.entsweb.co.uk/jobs-auditions/",
    "email_from" : "xxx",
    "email_to" : "xxx",
    "smpt_host" : "xxx",
    "smtp_port" : "xxx",
    "smtp_user" : "xxx",
    "smtp_password" : "xxx",
    "email_subject" : "New Jobs",
}

r = requests.get(config["url"])
message_html = ""
message_text = ""

tree = html.fromstring( r.text.encode('utf-8') )

for job_node in tree.xpath('//div[@class="jobs-item"]'):
    job = {}
    
    job["title"] = job_node.xpath('.//h3/a/text()')[0]
    job["url"] = job_node.xpath('.//h3/a/@href')[0]
    job["url"] = config["url"] + job["url"]
    job["location"] = job_node.xpath('.//p[@class="location"]/strong/text()')[0]
    job["description"] = job_node.xpath('.//p[@class="location"]/following-sibling::p[1]/text()')[0]
    
    message_html += format_html(job)
    message_text += format_text(job)
    
send_email(message_html, message_text)
    
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Spyder stopped working in Windows 10 gammaray 3 3,031 Apr-19-2021, 05:33 PM
Last Post: jefsummers
  for loop script over telnet in Python 3.5 is not working abhijithd123 1 2,860 May-10-2020, 03:22 AM
Last Post: bowlofred
  countdown script not working..plz help what is mistake randyjack 1 2,080 Oct-28-2019, 06:57 AM
Last Post: perfringo
  picamera not working on premade script georgeaura 1 2,484 Jul-24-2019, 10:11 AM
Last Post: gontajones
  python has stopped working sally 1 5,990 Nov-22-2018, 10:19 PM
Last Post: metulburr
  mkdtemp spontaneously stopped working reliably last night saporta98 1 2,790 Apr-16-2018, 05:12 PM
Last Post: nilamo
  Stopped process is still running pawlaczkaj 9 4,509 Apr-08-2018, 10:22 AM
Last Post: Gribouillis
  urlparse to urllib.parse - the script stopped working apollo 5 6,618 Oct-26-2017, 06:57 AM
Last Post: apollo
  Logging module stopped working! llanitedave 1 7,868 Oct-18-2017, 06:45 AM
Last Post: llanitedave
  [split] Script has stopped working santhosh 1 3,155 Feb-27-2017, 03:21 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020