bs4.element.Tag causes pickle to go into infinite recursion

Reported by Yaroslav Halchenko on 2013-09-26
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Beautiful Soup
Undecided
Unassigned

Bug Description

% python bs4-fails-cpickle.py
4.2.1
<class 'bs4.element.Tag'>
<a class="skippy" href="#skip">Skip Navigation</a>
cPickle failed with maximum recursion depth exceeded while getting the str of an object
pickle failed with maximum recursion depth exceeded

% PYTHONPATH=/home/yoh/proj/misc/beautifulsoup python bs4-fails-cpickle.py
4.3.1
<class 'bs4.element.Tag'>
<a class="skippy" href="#skip">Skip Navigation</a>
cPickle failed with maximum recursion depth exceeded while getting the str of an object
pickle failed with maximum recursion depth exceeded

% cat bs4-fails-cpickle.py
#!/usr/bin/python
#emacs: -*- mode: python-mode; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-
#ex: set sts=4 ts=4 sw=4 noet:
"""

 COPYRIGHT: Yaroslav Halchenko 2013

 LICENSE: MIT

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
"""

__author__ = 'Yaroslav Halchenko'
__copyright__ = 'Copyright (c) 2013 Yaroslav Halchenko'
__license__ = 'MIT'

import urllib2
import bs4
from bs4 import BeautifulSoup

print bs4.__version__

page = urllib2.urlopen('http://videocast.nih.gov/pastevents.asp')
soup = BeautifulSoup(page)
a = soup.find(text='Skip Navigation').parent
print type(a)
print a

try:
    from cPickle import Pickler
    with open('/tmp/bs4-fails-cpickle.dat', 'w') as f:
        Pickler(f).dump(a)
except Exception, e:
    print "cPickle failed with ", e

try:
    from pickle import Pickler
    with open('/tmp/bs4-fails-cpickle.dat', 'w') as f:
        Pickler(f).dump(a)
except Exception, e:
    print "pickle failed with ", e

Leonard Richardson (leonardr) wrote :

Unfortunately I can't retrieve your example page because the federal government is shut down. Can you provide a minimal set of markup that crashes pickle? There are existing pickle tests (in test_tree.py#TestPersistence), but I'm not surprised to find that it doesn't always work.

Yaroslav Halchenko (yarikoptic) wrote :

here is a copy of one of those pages http://www.onerussian.com/tmp/pastevents.asp.html
unfortunately I haven't managed to come up with a minimal markup yet

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers