Maximum Recursion Error Python
Solution 1:
This exception from pickle.dump usually means that you're trying to pickle an object that contains itself (directly or indirectly).
But what object contains itself? When you print
them all out, they all look fine.
It's awayTeam
This is a bs4.element.NavigableString
, which you get by doing this:
awayTeam = awayQTRScores[0]
You may not notice it from just print awayTeam
or even print repr(awayTeam)
, because NavigableString
is a subclass of unicode
and doesn't define a custom __str__
or __repr__
, so it prints just like a string.
But it also doesn't define a custom pickler, so it uses the default pickler. In general, bs4
objects aren't designed to be pickled, and many of them can't be. In particular, NavigableString
is an object that indirectly contains itself. As the docs say:
If you want to use a
NavigableString
outside of Beautiful Soup, you should callunicode()
on it to turn it into a normal Python Unicode string. If you don’t, your string will carry around a reference to the entire Beautiful Soup parse tree, even when you’re done using Beautiful Soup.
And of course the parse tree contains a reference to the string, which etc. So, this type can never be pickled.
The solution is simple. You wanted a plain old unicode
string, not a NavigableString
, so you can just do this:
awayTeam = unicode(awayQTRScores[0])
Post a Comment for "Maximum Recursion Error Python"