python-wordpress-xmlrpc icon indicating copy to clipboard operation
python-wordpress-xmlrpc copied to clipboard

How to fix "module 'collections' has no attribute 'Iterable'" error

Open devtonic-net opened this issue 2 years ago • 6 comments

When trying to retrieve a list of WordPress posts, I got the error module 'collections' has no attribute 'Iterable'. This is because in Python 3.10, the version I was using, the Iterable class has been moved to the collections.abc module.

In order to solve this error, after installing the library with pip install python-wordpress-xmlrpc, open the wordpress_xmlrpc folder (it should be in your virtual environment), then open the file base.py.

Here, you need to make two replacements:

  1. At line 1, replace import collections with import collections.abc
  2. At line 128, replace elif isinstance(raw_result, collections.Iterable): with elif isinstance(raw_result, collections.abc.Iterable):

That should fix the error and allow the script to parse the raw result from the WordPress site.

devtonic-net avatar Jan 12 '23 14:01 devtonic-net

THANK YOU!!!!!Lost my whole morning and part of yesterday evening trying to fix this without understanding why was giving problem. My project was working in another venv probably with an older interpreter a lost that project started from scratch and was getting crazy why something that was working before is not working now!BIG THANK YOU again

acleitao-projects avatar Apr 02 '23 14:04 acleitao-projects

Nice! I'm glad you fixed it. Although I really appreciate this library - it's pretty straightforward - , I decided to switch to WP REST API, which is a lot more versatile.

devtonic-net avatar Apr 02 '23 19:04 devtonic-net

Actually I use wordpress like forever, I use Python for small things but never join both of them. Chatgpt recommended me this library so I just got to learn there are better ones after 2000 lines of code were done lol. But again dude you saved my day! Own you a coffee!

acleitao-projects avatar Apr 02 '23 19:04 acleitao-projects

No problem, such is the beauty of internet :)

devtonic-net avatar Apr 02 '23 19:04 devtonic-net

I wish i saw this earlier. I have a pull request for it ready to go if the author is so inclined: https://github.com/maxcutler/python-wordpress-xmlrpc/pull/156 @maxcutler

thijs-hakkenberg avatar Sep 05 '23 23:09 thijs-hakkenberg

Thanks =D

wpraiz avatar Mar 13 '24 05:03 wpraiz