I am running into a weird error with spynner, though the question is a generic one. Spynner is the stateful web-browser module for python. It works fine when it works but I almost with every run I get a failure saying this --
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/spynner-2.16.dev0-py2.7.egg/spynner/browser.py", line 1651, in createRequest
self.cookies,
AttributeError: 'Browser' object has no attribute 'cookies'
Segmentation fault (core dumped)
The problem here is its segfaulting and not letting me continue.
Looking at the code for spynner I see that the cookies variable is in fact initialized in the __init__()
function for the Browser class like this:
self.cookies = []
Now on failure its really saying that the __init__()
is not run since its not seeing the cookies variable. I do not understand how that can be possible. Without restricting to the spynner module can someone venture a guess as to how a python object could fail with an error like this?
EDIT: I definitely would have pasted my code here except its not all in one place for me to compactly show it. I should have done it earlier but here is the overall structure and how I instantiate and use spynner.
# helper class to get url data
class C:
def __init__(self):
self.browser = spynner.Browser()
def get_data(self, url):
try:
self.browser.load(url)
return self.browser.html
except:
raise
# class that does other stuff among saving url data to disk
class B:
def save_url_to_disk(self, url):
urlObj = C()
html = urlObj.get_data(url)
# do stuff with html
# class that drives everything
class A:
def do_stuff_and_save_url_data(self, url):
fileObj = B()
fileObj.save_url_to_disk(url)
driver = A()
# call this function for multiple URLs.
driver.do_stuff_and_save_url_data(url)
The way I run it is ---
# xvfb-run python myfile.py
The segfault is probably something else I am doing. May be its because of the xvfb I am using and not handling properly? I don't know yet. I need to mention that I am relatively new to python.
I noticed that when I run the code above with say 'http://www.google.com' I get the segfault every other time.