socket error ([Erno 32] Socket closed)

Asked by pxpvisual

Hi!

I am a brand new user of sikuli (and almost a noob at coding) and I'm using it for an Interaction Design project.

Recently I had an error while trying to connect to the internet to parse some html via the Sikuli IDE (I'm using the latest version of Sikulix, MAC, Yosemite 10.10.1 and I use LittleSnitch, but turn it off for testing purpose).

When I run my sript I get this error:

[error] script [ fiznik ] stopped with error in line 29
[error] socket.error ( [Errno 32] Socket closed )
[error] --- Traceback --- error source first
line: module ( function ) statement
174: socket ( handle_exception ) socket.error: [Errno 32] Socket closed
585: httplib ( _read_chunked ) File "/Users/PXP/Documents/SIKULI/sikulix.jar/Lib/socket.py", line 1733, in readline
1651: socket ( read ) File "/Users/PXP/Documents/SIKULI/sikulix.jar/Lib/httplib.py", line 543, in read
[error] --- Traceback --- end --------------

and this is the code

from HTMLParser import HTMLParser
import urllib2

ignoredLinks = ["[","]"," N "]
linklist = []

class MyHTMLParser(HTMLParser):
 def __init__(self):
  HTMLParser.__init__(self)
  self.currentLink = None
  self.inParagraph = False

 def handle_starttag(self, tag, attrs):
  if(tag=='p'): self.inParagraph = True
  elif(self.inParagraph==True and tag=="a"):
   self.currentLink = ""

 def handle_endtag(self, tag):
  if(tag=='p'): self.inParagraph = False
  elif(tag=="a" and self.currentLink!=None and len(self.currentLink)>2):
   if not any(match in self.currentLink for match in ignoredLinks):
    linklist.append(self.currentLink)
    self.currentLink = None

 def handle_data(self, data):
  if self.currentLink!=None: self.currentLink+=data

req = urllib2.urlopen("https://fr.wikipedia.org/wiki/Lausanne")
html = req.read()
html = unicode(html, req.headers['content-type'].split('charset=')[-1])

parser = MyHTMLParser()
parser.feed(html)

i = 0
for link in linklist:
 i+=1
 print i,":",link

The error seems to happen at html = req.read()

When I run it in a .py file using terminal it works perfectly and retrieves all I need but as you see when I run it from sikulix, something seems to interrupt the process...

Does anyone have an answer? It would be awesome, as my project is the first step for my Bachelor thesis!

PXP

Question information

Language:
English Edit question
Status:
Expired
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

I guess, when you say:
When I run it in a .py file using terminal ...

you are using the Python interpreter.

SikuliX, since it is Java based, uses the Jython interpreter, which is to 95%+ compatible to the Python interpreter at language level 2.7 (the Jython we use internally is 2.7Beta1 or 2.7Beta3).

so if it does not work inside a Sikuli script, you either have to find the reason and fix it or use other means to get the content of the requested webpage for parsing.

In any case: please give exact information about your environment and the build version of SikuliX.

Revision history for this message
Launchpad Janitor (janitor) said :
#2

This question was expired because it remained in the 'Needs information' state without activity for the last 15 days.